Skip to content

Commit

Permalink
Merge pull request #1885 from embroider-build/portable-babel-launcher
Browse files Browse the repository at this point in the history
Fix pre support in portable babel launcher
  • Loading branch information
ef4 committed Apr 18, 2024
2 parents a10ef00 + cecb190 commit 2636437
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 18 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,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": {
Expand Down
6 changes: 3 additions & 3 deletions packages/core/src/portable-babel-launcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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));
};
}

Expand Down
6 changes: 2 additions & 4 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 8 additions & 8 deletions tests/scenarios/compat-resolver-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 }),
});
`,
});
Expand All @@ -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 }),
});
`);
});
Expand All @@ -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|}} <capitalize /> {{/each}}", {
scope: () => ({ thing }),
scope: () => ({ things }),
});
`,
});
Expand All @@ -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|}} <capitalize /> {{/each}}", {
scope: () => ({ thing }),
scope: () => ({ things }),
});
`);
});
Expand All @@ -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|}} <div {{capitalize}} /> {{/each}}", {
scope: () => ({ thing }),
scope: () => ({ things }),
});
`,
});
Expand All @@ -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|}} <div {{capitalize}} /> {{/each}}", {
scope: () => ({ thing }),
scope: () => ({ things }),
});
`);
});
Expand All @@ -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 }),
});
`,
});
Expand All @@ -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 }),
});
`);
});
Expand Down
4 changes: 2 additions & 2 deletions tests/scenarios/stage1-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ appScenarios
);

fileContents.matches(
/hbs\(["']<div class={{embroider-sample-transforms-result}}>Extra<\/div>["']\)/,
/precompileTemplate\(["']<div class={{embroider-sample-transforms-result}}>Extra<\/div>["']\)/,
'called template is still hbs and custom transforms have run'
);

Expand Down Expand Up @@ -188,7 +188,7 @@ appScenarios
);

file.matches(
/hbs\(["']<div class={{embroider-sample-transforms-result}}>Extra<\/div>["']\)/,
/precompileTemplate\(["']<div class={{embroider-sample-transforms-result}}>Extra<\/div>["']\)/,
'called template is still hbs and custom transforms have run'
);

Expand Down

0 comments on commit 2636437

Please sign in to comment.