From 1a39b4c7c024b2ca871b78971f9f371b10919bd0 Mon Sep 17 00:00:00 2001 From: Edward Faulkner Date: Thu, 18 Apr 2024 10:02:30 -0400 Subject: [PATCH] Merge pull request #1885 from embroider-build/portable-babel-launcher Fix pre support in portable babel launcher --- package.json | 3 ++- packages/core/src/portable-babel-launcher.ts | 6 +++--- pnpm-lock.yaml | 4 +--- tests/scenarios/compat-resolver-test.ts | 16 ++++++++-------- tests/scenarios/stage1-test.ts | 4 ++-- 5 files changed, 16 insertions(+), 17 deletions(-) diff --git a/package.json b/package.json index 5e063ceaa9..7db621263a 100644 --- a/package.json +++ b/package.json @@ -33,7 +33,8 @@ "overrides": { "browserslist": "^4.14.0", "graceful-fs": "^4.0.0", - "@types/eslint": "^8.37.0" + "@types/eslint": "^8.37.0", + "babel-plugin-module-resolver@5.0.1": "5.0.0" } }, "devDependencies": { diff --git a/packages/core/src/portable-babel-launcher.ts b/packages/core/src/portable-babel-launcher.ts index a7ae6b2f25..12e383845d 100644 --- a/packages/core/src/portable-babel-launcher.ts +++ b/packages/core/src/portable-babel-launcher.ts @@ -34,15 +34,15 @@ export default function babelLauncher( function wrap1(original: any) { if (typeof original === 'function') { - return function (this: any, state: any) { - return original.call(this, convertState(state)); + return function (this: any, file: any) { + return original.call(convertState(this), file); }; } } function wrap2(original: Function) { return function (this: any, path: any, state: any) { - return original.call(this, path, convertState(state)); + return original.call(convertState(this), path, convertState(state)); }; } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 0f0b120723..69d4b9d0a9 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -8,6 +8,7 @@ overrides: browserslist: ^4.14.0 graceful-fs: ^4.0.0 '@types/eslint': ^8.37.0 + babel-plugin-module-resolver@5.0.1: 5.0.0 importers: @@ -9630,9 +9631,6 @@ packages: /ajv-formats@2.1.1: resolution: {integrity: sha512-Wx0Kx52hxE7C18hkMEggYlEifqWZtYaRgouJor+WMdPnQyEK13vgEWyVNup7SoeeoLMsr4kf5h6dOW11I15MUA==} - peerDependenciesMeta: - ajv: - optional: true dependencies: ajv: 8.12.0 diff --git a/tests/scenarios/compat-resolver-test.ts b/tests/scenarios/compat-resolver-test.ts index 5823973382..1141e72b73 100644 --- a/tests/scenarios/compat-resolver-test.ts +++ b/tests/scenarios/compat-resolver-test.ts @@ -1406,7 +1406,7 @@ Scenarios.fromProject(() => new Project()) 'templates/application.hbs.js': ` import { precompileTemplate } from '@ember/template-compilation'; export default precompileTemplate("{{#each things as |capitalize|}} {{(capitalize)}} {{/each}}", { - scope: () => ({ thing }), + scope: () => ({ things }), }); `, }); @@ -1416,7 +1416,7 @@ Scenarios.fromProject(() => new Project()) expectTranspiled('templates/application.hbs.js').equalsCode(` import { precompileTemplate } from '@ember/template-compilation'; export default precompileTemplate("{{#each things as |capitalize|}} {{(capitalize)}} {{/each}}", { - scope: () => ({ thing }), + scope: () => ({ things }), }); `); }); @@ -1426,7 +1426,7 @@ Scenarios.fromProject(() => new Project()) 'templates/application.hbs.js': ` import { precompileTemplate } from '@ember/template-compilation'; export default precompileTemplate("{{#each things as |capitalize|}} {{/each}}", { - scope: () => ({ thing }), + scope: () => ({ things }), }); `, }); @@ -1436,7 +1436,7 @@ Scenarios.fromProject(() => new Project()) expectTranspiled('templates/application.hbs.js').equalsCode(` import { precompileTemplate } from '@ember/template-compilation'; export default precompileTemplate("{{#each things as |capitalize|}} {{/each}}", { - scope: () => ({ thing }), + scope: () => ({ things }), }); `); }); @@ -1446,7 +1446,7 @@ Scenarios.fromProject(() => new Project()) 'templates/application.hbs.js': ` import { precompileTemplate } from '@ember/template-compilation'; export default precompileTemplate("{{#each things as |capitalize|}}
{{/each}}", { - scope: () => ({ thing }), + scope: () => ({ things }), }); `, }); @@ -1456,7 +1456,7 @@ Scenarios.fromProject(() => new Project()) expectTranspiled('templates/application.hbs.js').equalsCode(` import { precompileTemplate } from '@ember/template-compilation'; export default precompileTemplate("{{#each things as |capitalize|}}
{{/each}}", { - scope: () => ({ thing }), + scope: () => ({ things }), }); `); }); @@ -1466,7 +1466,7 @@ Scenarios.fromProject(() => new Project()) 'templates/application.hbs.js': ` import { precompileTemplate } from '@ember/template-compilation'; export default precompileTemplate("{{#each things as |capitalize|}} {{capitalize 1}} {{/each}}", { - scope: () => ({ thing }), + scope: () => ({ things }), }); `, }); @@ -1476,7 +1476,7 @@ Scenarios.fromProject(() => new Project()) expectTranspiled('templates/application.hbs.js').equalsCode(` import { precompileTemplate } from '@ember/template-compilation'; export default precompileTemplate("{{#each things as |capitalize|}} {{capitalize 1}} {{/each}}", { - scope: () => ({ thing }), + scope: () => ({ things }), }); `); }); diff --git a/tests/scenarios/stage1-test.ts b/tests/scenarios/stage1-test.ts index a8ed7f20e8..7ef47da99f 100644 --- a/tests/scenarios/stage1-test.ts +++ b/tests/scenarios/stage1-test.ts @@ -141,7 +141,7 @@ appScenarios ); fileContents.matches( - /hbs\(["']
Extra<\/div>["']\)/, + /precompileTemplate\(["']
Extra<\/div>["']\)/, 'called template is still hbs and custom transforms have run' ); @@ -219,7 +219,7 @@ appScenarios ); file.matches( - /hbs\(["']
Extra<\/div>["']\)/, + /precompileTemplate\(["']
Extra<\/div>["']\)/, 'called template is still hbs and custom transforms have run' );