Skip to content

Commit

Permalink
Revert "WIP - put utilities to be stripped in their own package, so w…
Browse files Browse the repository at this point in the history
…e can inline the package"

This reverts commit 57406f687a7991b8b35c907b1e7483bb40a4d521.
  • Loading branch information
NullVoxPopuli committed Sep 8, 2024
1 parent 9780f6c commit 287ab1a
Show file tree
Hide file tree
Showing 14 changed files with 747 additions and 1,026 deletions.
13 changes: 3 additions & 10 deletions packages/@glimmer-workspace/build/lib/config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/* eslint-disable no-console */
// @ts-check
import { existsSync, readFileSync } from 'node:fs';
import { createRequire } from 'node:module';
import { dirname, resolve } from 'node:path';
import { fileURLToPath } from 'node:url';

Expand All @@ -13,8 +12,6 @@ import ts from 'typescript';

import inline from './inline.js';

const require = createRequire(import.meta.url);

// eslint-disable-next-line import/no-named-as-default-member
const { ModuleKind, ModuleResolutionKind, ScriptTarget, ImportsNotUsedAsValues } = ts;

Expand Down Expand Up @@ -109,7 +106,7 @@ export function typescript(pkg, config) {

/** @type {['is' | 'startsWith', string[], 'inline' | 'external'][]} */
const EXTERNAL_OPTIONS = [
['is', ['tslib', '@glimmer/local-debug-flags', '@glimmer/local-debug-utils'], 'inline'],
['is', ['tslib', '@glimmer/local-debug-flags'], 'inline'],
['is', ['@handlebars/parser', 'simple-html-tokenizer', 'babel-plugin-debug-macros'], 'external'],
['startsWith', ['.', '/', '#', '@babel/runtime/', process.cwd().replace(/\\/gu, '/')], 'inline'],
['startsWith', ['@glimmer/', '@simple-dom/', '@babel/', 'node:'], 'external'],
Expand Down Expand Up @@ -324,7 +321,7 @@ export class Package {
// identifiers, unchanged
// mangle: false,
compress: {
passes: 4,
passes: 3,
},
}),
]
Expand All @@ -333,7 +330,7 @@ export class Package {
module: true,
mangle: false,
compress: {
passes: 4,
passes: 3,
},
format: {
comments: 'all',
Expand Down Expand Up @@ -455,14 +452,10 @@ export class Package {

return {
input: resolve(root, ts),
treeshake: {
moduleSideEffects: false,
},
output: {
file: resolve(root, 'dist', env, file),
format,
sourcemap: true,
hoistTransitiveImports: false,
exports: format === 'cjs' ? 'named' : 'auto',
},
onwarn: (warning, warn) => {
Expand Down
48 changes: 29 additions & 19 deletions packages/@glimmer/debug/index.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,31 @@
export { debug, debugSlice, logOpcode } from './lib/debug';
export * from './lib/metadata';
export { opcodeMetadata } from './lib/opcode-metadata';
export type { Checker } from './lib/stack-check';
export {
OPERAND_TYPES,
type OperandType,
type Operand,
type OperandList,
type NormalizedMetadata,
type Stack,
type RawOperandMetadata,
type OperandName,
type RawOperandFormat,
normalize,
type NormalizedOpcodes,
normalizeAll,
normalizeParsed,
buildEnum,
strip,
META_KIND,
buildSingleMeta,
buildMetas,
} from './lib/metadata';
check,
CheckArray,
CheckBlockSymbolTable,
CheckBoolean,
CheckDict,
CheckDocumentFragment,
CheckElement,
CheckFunction,
CheckHandle,
CheckInstanceof,
CheckInterface,
CheckMaybe,
CheckNode,
CheckNumber,
CheckObject,
CheckOption,
CheckOr,
CheckPrimitive,
CheckProgramSymbolTable,
CheckSafeString,
CheckString,
CheckUndefined,
CheckUnknown,
recordStackSize,
wrap,
} from './lib/stack-check';
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@ import type {
TemplateCompilationContext,
} from '@glimmer/interfaces';
import type { Register } from '@glimmer/vm';
import { opcodeMetadata } from '@glimmer/debug';
import { LOCAL_SHOULD_LOG } from '@glimmer/local-debug-flags';
import { decodeHandle, decodeImmediate, enumerate, LOCAL_LOGGER } from '@glimmer/util';
import { $fp, $pc, $ra, $s0, $s1, $sp, $t0, $t1, $v0 } from '@glimmer/vm';

import type { Primitive } from './stack-check';

import { opcodeMetadata } from './opcode-metadata';

export interface DebugConstants {
getValue<T>(handle: number): T;
getArray<T>(value: number): T[];
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion packages/@glimmer/debug/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
"@glimmer/local-debug-flags": "workspace:^",
"eslint": "^8.52.0",
"publint": "^0.2.5",
"rollup": "^4.21.2",
"rollup": "^4.5.1",
"toml": "^3.0.0",
"typescript": "*"
}
Expand Down
29 changes: 0 additions & 29 deletions packages/@glimmer/local-debug-utils/index.ts

This file was deleted.

30 changes: 0 additions & 30 deletions packages/@glimmer/local-debug-utils/package.json

This file was deleted.

3 changes: 0 additions & 3 deletions packages/@glimmer/local-debug-utils/rollup.config.mjs

This file was deleted.

4 changes: 2 additions & 2 deletions packages/@glimmer/manager/lib/util/capabilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,14 +104,14 @@ export function managerHasCapability<F extends InternalComponentCapability>(
capabilities: CapabilityMask,
capability: F
): _manager is InternalComponentCapabilityFor<F> {
import.meta.env.DEV && check(capabilities, CheckNumber);
check(capabilities, CheckNumber);
return !!(capabilities & capability);
}

export function hasCapability(
capabilities: CapabilityMask,
capability: InternalComponentCapability
): boolean {
import.meta.env.DEV && check(capabilities, CheckNumber);
check(capabilities, CheckNumber);
return !!(capabilities & capability);
}
54 changes: 12 additions & 42 deletions packages/@glimmer/runtime/lib/compiled/opcodes/content.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
import type { SafeString } from '@glimmer/debug/lib/stack-check';
import type { SimpleDocumentFragment, SimpleNode } from '@glimmer/interfaces';
import type { Reference } from '@glimmer/reference';
import {
check,
CheckDocumentFragment,
Expand Down Expand Up @@ -67,9 +64,7 @@ function toDynamicContentType(value: unknown) {
}

APPEND_OPCODES.add(Op.ContentType, (vm) => {
let reference: Reference<unknown> = import.meta.env.DEV
? check(vm.stack.peek(), CheckReference)
: vm.stack.peek();
let reference = check(vm.stack.peek(), CheckReference);

vm.stack.push(toContentType(valueForRef(reference)));

Expand All @@ -79,9 +74,7 @@ APPEND_OPCODES.add(Op.ContentType, (vm) => {
});

APPEND_OPCODES.add(Op.DynamicContentType, (vm) => {
let reference: Reference<unknown> = import.meta.env.DEV
? check(vm.stack.peek(), CheckReference)
: vm.stack.peek();
let reference = check(vm.stack.peek(), CheckReference);

vm.stack.push(toDynamicContentType(valueForRef(reference)));

Expand All @@ -91,9 +84,7 @@ APPEND_OPCODES.add(Op.DynamicContentType, (vm) => {
});

APPEND_OPCODES.add(Op.AppendHTML, (vm) => {
let reference: Reference<unknown> = import.meta.env.DEV
? check(vm.stack.pop(), CheckReference)
: vm.stack.pop();
let reference = check(vm.stack.pop(), CheckReference);

let rawValue = valueForRef(reference);
let value = isEmpty(rawValue) ? '' : String(rawValue);
Expand All @@ -102,29 +93,16 @@ APPEND_OPCODES.add(Op.AppendHTML, (vm) => {
});

APPEND_OPCODES.add(Op.AppendSafeHTML, (vm) => {
let reference: Reference<unknown> = import.meta.env.DEV
? check(vm.stack.pop(), CheckReference)
: vm.stack.pop();

let rawValue: string = (
import.meta.env.DEV
? check(valueForRef(reference), CheckSafeString)
: (valueForRef(reference) as SafeString)
).toHTML();

let value = isEmpty(rawValue)
? ''
: import.meta.env.DEV
? check(rawValue, CheckString)
: rawValue;
let reference = check(vm.stack.pop(), CheckReference);

let rawValue = check(valueForRef(reference), CheckSafeString).toHTML();
let value = isEmpty(rawValue) ? '' : check(rawValue, CheckString);

vm.elements().appendDynamicHTML(value);
});

APPEND_OPCODES.add(Op.AppendText, (vm) => {
let reference: Reference<unknown> = import.meta.env.DEV
? check(vm.stack.pop(), CheckReference)
: vm.stack.pop();
let reference = check(vm.stack.pop(), CheckReference);

let rawValue = valueForRef(reference);
let value = isEmpty(rawValue) ? '' : String(rawValue);
Expand All @@ -137,25 +115,17 @@ APPEND_OPCODES.add(Op.AppendText, (vm) => {
});

APPEND_OPCODES.add(Op.AppendDocumentFragment, (vm) => {
let reference: Reference<unknown> = import.meta.env.DEV
? check(vm.stack.pop(), CheckReference)
: vm.stack.pop();
let reference = check(vm.stack.pop(), CheckReference);

let value: SimpleDocumentFragment = import.meta.env.DEV
? check(valueForRef(reference), CheckDocumentFragment)
: (valueForRef(reference) as SimpleDocumentFragment);
let value = check(valueForRef(reference), CheckDocumentFragment);

vm.elements().appendDynamicFragment(value);
});

APPEND_OPCODES.add(Op.AppendNode, (vm) => {
let reference: Reference<unknown> = import.meta.env.DEV
? check(vm.stack.pop(), CheckReference)
: vm.stack.pop();
let reference = check(vm.stack.pop(), CheckReference);

let value: SimpleNode = import.meta.env.DEV
? check(valueForRef(reference), CheckNode)
: (valueForRef(reference) as SimpleNode);
let value = check(valueForRef(reference), CheckNode);

vm.elements().appendDynamicNode(value);
});
5 changes: 1 addition & 4 deletions packages/@glimmer/runtime/lib/compiled/opcodes/dom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,7 @@ APPEND_OPCODES.add(Op.OpenElement, (vm, { op1: tag }) => {
});

APPEND_OPCODES.add(Op.OpenDynamicElement, (vm) => {
let tagName = import.meta.env.DEV
? check(valueForRef(check(vm.stack.pop(), CheckReference)), CheckString)
: // eslint-disable-next-line
valueForRef(vm.stack.pop() as Reference<string>);
let tagName = check(valueForRef(check(vm.stack.pop(), CheckReference)), CheckString);
vm.elements().openElement(tagName);
});

Expand Down
Loading

0 comments on commit 287ab1a

Please sign in to comment.