Skip to content

Commit

Permalink
revert #22: keep inline context order to support nested dsl merge
Browse files Browse the repository at this point in the history
  • Loading branch information
mistlog committed Jul 24, 2020
1 parent a8e036e commit 6a7a507
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 8 deletions.
6 changes: 2 additions & 4 deletions src/code-object/inline-context.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,11 @@ export class InlineContext {

<InlineContext /> +
function Resolve(this: InlineContext & IInlineContext, dsl: IDSL) {
const resolved = dsl.Transcribe(this.ToStatements(), this.m_Path);
if (dsl.m_Merge) {
this.m_Path.insertAfter(resolved);
this.m_Path.replaceWithMultiple(dsl.Transcribe(this.ToStatements(), this.m_Path));
} else {
this.m_Path.insertAfter(blockStatement(resolved));
this.m_Code.body = dsl.Transcribe(this.ToStatements(), this.m_Path);
}
this.m_Path.remove();
};

<InlineContext /> +
Expand Down
5 changes: 4 additions & 1 deletion src/code-object/module.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,10 @@ export type Draft = Array<ExportClassCode | MethodCode | LocalContext | InlineCo
if (expression.isStringLiteral()) {
const literal = expression.node.value.trim();
if (literal.startsWith("use") && path.parentPath.isBlockStatement()) {
draft.push(new InlineContext(path.parentPath));
/**
* inline context should be resolved from deepest
*/
draft.unshift(new InlineContext(path.parentPath));
}
}
},
Expand Down
2 changes: 0 additions & 2 deletions test/plug-in/__snapshots__/dsl.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,6 @@ exports[`nested dsl 1`] = `
exports[`nested dsl: merge 1`] = `
"export function Main() {
$: {
\\"use watch\\";
if (value === \\"a\\") {
console.log(\\"value is a\\");
}
Expand Down
3 changes: 2 additions & 1 deletion test/plug-in/dsl.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,8 @@ test("nested dsl: merge", () => {
this.m_Merge = true;
}
Transcribe(block: Array<Statement>): Array<Statement> {
return [labeledStatement(identifier("$"), blockStatement(block))];
const [use_watch, ...rest] = block;
return [labeledStatement(identifier("$"), blockStatement(rest))];
}
}

Expand Down

0 comments on commit 6a7a507

Please sign in to comment.