Skip to content

Commit

Permalink
Checkpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
wycats committed Feb 5, 2025
1 parent 42882a0 commit 47d19c2
Show file tree
Hide file tree
Showing 36 changed files with 1,694 additions and 1,412 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ module('[glimmer-compiler] precompile', ({ test }) => {

let [statements] = wire.block;
let [[, componentNameExpr], ...divExpr] = statements as [
WireFormat.Statements.Component,
...WireFormat.Statement[],
WireFormat.Contents.Component,
...WireFormat.Content[],
];

assert.deepEqual(wire.scope?.(), [hello]);
Expand All @@ -80,8 +80,8 @@ module('[glimmer-compiler] precompile', ({ test }) => {

let [statements] = wire.block;
let [[, componentNameExpr], ...divExpr] = statements as [
WireFormat.Statements.Component,
...WireFormat.Statement[],
WireFormat.Contents.Component,
...WireFormat.Content[],
];

assert.deepEqual(wire.scope?.(), [f]);
Expand All @@ -108,7 +108,7 @@ module('[glimmer-compiler] precompile', ({ test }) => {
);

let block: WireFormat.SerializedTemplateBlock = JSON.parse(wire.block);
let [[, componentNameExpr]] = block[0] as [WireFormat.Statements.Component];
let [[, componentNameExpr]] = block[0] as [WireFormat.Contents.Component];

localAssert(
Array.isArray(componentNameExpr) &&
Expand All @@ -131,8 +131,8 @@ module('[glimmer-compiler] precompile', ({ test }) => {

let block: WireFormat.SerializedTemplateBlock = JSON.parse(wire.block);

let [[, , letBlock]] = block[0] as [WireFormat.Statements.Let];
let [[, componentNameExpr]] = letBlock[0] as [WireFormat.Statements.Component];
let [[, , letBlock]] = block[0] as [WireFormat.Contents.Let];
let [[, componentNameExpr]] = letBlock[0] as [WireFormat.Contents.Component];

localAssert(
Array.isArray(componentNameExpr) &&
Expand All @@ -155,7 +155,7 @@ module('[glimmer-compiler] precompile', ({ test }) => {

let block: WireFormat.SerializedTemplateBlock = JSON.parse(wire.block);

let [[, componentNameExpr]] = block[0] as [WireFormat.Statements.ResolvedBlock];
let [[, componentNameExpr]] = block[0] as [WireFormat.Contents.ResolvedBlock];

localAssert(
Array.isArray(componentNameExpr) &&
Expand All @@ -178,7 +178,7 @@ module('[glimmer-compiler] precompile', ({ test }) => {

let block: WireFormat.SerializedTemplateBlock = JSON.parse(wire.block);

let [[, componentNameExpr]] = block[0] as [WireFormat.Statements.ResolvedBlock];
let [[, componentNameExpr]] = block[0] as [WireFormat.Contents.ResolvedBlock];

localAssert(
Array.isArray(componentNameExpr) &&
Expand Down Expand Up @@ -214,17 +214,21 @@ module('[glimmer-compiler] precompile', ({ test }) => {
test('when "this" in in locals, it compiles to GetLexicalSymbol', (assert) => {
let target = { message: 'hello' };
let _wire: ReturnType<typeof compile>;
(function() {
(function () {
_wire = compile(`{{this.message}}`, ['this'], (source) => eval(source));
}).call(target)
}).call(target);
let wire = _wire!;
assert.deepEqual(wire.scope?.(), [target]);
assert.deepEqual(wire.block[0], [[SexpOpcodes.Append,[SexpOpcodes.GetLexicalSymbol,0,["message"]]]])
assert.deepEqual(wire.block[0], [
[SexpOpcodes.Append, [SexpOpcodes.GetLexicalSymbol, 0, ['message']]],
]);
});

test('when "this" is not in locals, it compiles to GetSymbol', (assert) => {
test('when "this" is not in locals, it compiles to GetSymbolOrPath', (assert) => {
let wire = compile(`{{this.message}}`, [], (source) => eval(source));
assert.strictEqual(wire.scope, undefined);
assert.deepEqual(wire.block[0], [[SexpOpcodes.Append,[SexpOpcodes.GetSymbol,0,["message"]]]])
assert.deepEqual(wire.block[0], [
[SexpOpcodes.Append, [SexpOpcodes.GetLocalSymbol, 0, ['message']]],
]);
});
});
12 changes: 6 additions & 6 deletions packages/@glimmer/compiler/index.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
export { ProgramSymbols } from './lib/builder/builder';
export { defaultId, precompile, precompileJSON, type PrecompileOptions } from './lib/compiler';

// exported only for tests!
export type { BuilderStatement } from './lib/builder/test-support/builder-interface';
export {
buildStatement,
buildStatements,
c,
NEWLINE,
ProgramSymbols,
s,
unicode,
} from './lib/builder/builder';
export { type BuilderStatement } from './lib/builder/builder-interface';
export { defaultId, precompile, precompileJSON, type PrecompileOptions } from './lib/compiler';

// exported only for tests!
} from './lib/builder/test-support/test-support';
export { default as WireFormatDebugger } from './lib/wire-format-debug';
Loading

0 comments on commit 47d19c2

Please sign in to comment.