Skip to content

Commit

Permalink
Fixed the ember-template-import issue and updated the associated PR
Browse files Browse the repository at this point in the history
  • Loading branch information
github-actions[bot] committed Mar 31, 2023
1 parent 8ded688 commit ace80e7
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 13 deletions.
1 change: 0 additions & 1 deletion apps/repl/tests/application/output-demos-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@ module('Output > Demos', function (hooks) {

makeComponent('glimdown', text);
await settled();
await this.pauseTest();

assert.verifySteps(['begin compile', 'success', 'finished rendering']);
});
Expand Down
1 change: 1 addition & 0 deletions packages/ember-repl/addon/cjs/eti/babel-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ import type { CallExpression, Class, Program } from '@babel/types';
*/
export default function (babel: any) {
let t = babel.types;

let visitor: any = {
Program: {
enter(path: NodePath<Program>, state: any) {
Expand Down
25 changes: 25 additions & 0 deletions packages/ember-repl/addon/cjs/eti/parse-templates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ const newLine = /\n/;
const multiLineCommentStart = /\/\*/;
const multiLineCommentEnd = /\*\//;

const templateLiteralStart = /([$a-zA-Z_][0-9a-zA-Z_$]*)?`/;
const templateLiteralEnd = /`/;

const dynamicSegmentStart = /\${/;
const blockStart = /{/;
const dynamicSegmentEnd = /}/;
Expand Down Expand Up @@ -104,6 +107,8 @@ export function parseTemplates(
multiLineCommentStart.source,
multiLineCommentEnd.source,
stringDelimiter.source,
templateLiteralStart.source,
templateLiteralEnd.source,
dynamicSegmentStart.source,
dynamicSegmentEnd.source,
blockStart.source,
Expand Down Expand Up @@ -136,6 +141,8 @@ export function parseTemplates(
parseMultiLineComment(results, template, token, tokens);
} else if (token[0].match(singleLineCommentStart)) {
parseSingleLineComment(results, template, token, tokens);
} else if (token[0].match(templateLiteralStart)) {
parseTemplateLiteral(template, tokens);
} else if (
isTopLevel &&
templateTag !== undefined &&
Expand All @@ -148,6 +155,24 @@ export function parseTemplates(
}
}

/**
* Parse a template literal. If a dynamic segment is found, enters the dynamic
* segment and parses it recursively. If no dynamic segments are found and the
* literal is top level (e.g. not nested within a dynamic segment) and has a
* tag, pushes it into the list of results.
*/
function parseTemplateLiteral(template: string, tokens: RegExpMatchArray[]) {
while (tokens.length > 0) {
let currentToken = expect(tokens.shift(), 'expected token');

if (isEscaped(template, currentToken.index)) continue;

if (currentToken[0].match(templateLiteralEnd)) {
return;
}
}
}

/**
* Parse a string. All tokens within a string are ignored
* since there are no dynamic segments within these.
Expand Down
29 changes: 17 additions & 12 deletions packages/ember-repl/addon/cjs/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,19 @@ async function compileGJS({ code: input, name }: Info) {
babel = await import('@babel/standalone');
}

let preprocessed = preprocess(input, name);
let result = transformIntermediate(preprocessed, name);

if (!result) {
return;
}

let { code } = result;

return code;
}

function preprocess(input: string, name: string) {
let preprocessed = preprocessEmbeddedTemplates(input, {
relativePath: `${name}.js`,
includeSourceMaps: false,
Expand All @@ -51,9 +64,11 @@ async function compileGJS({ code: input, name }: Info) {
templateTagReplacement: TEMPLATE_TAG_PLACEHOLDER,
});

console.log(preprocessed.output);
return preprocessed.output;
}

let result = babel.transform(preprocessed.output, {
function transformIntermediate(intermediate: string, name: string) {
return babel.transform(intermediate, {
filename: `${name}.js`,
plugins: [
[babelPluginIntermediateGJS],
Expand All @@ -78,14 +93,4 @@ async function compileGJS({ code: input, name }: Info) {
],
],
});

if (!result) {
return;
}

let { code } = result;

console.log({ code });

return code;
}

0 comments on commit ace80e7

Please sign in to comment.