Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TS transform breaks imports in templates #30

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 72 additions & 0 deletions __tests__/tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import HTMLBarsInlinePrecompile, { Options } from '..';
import TransformTemplateLiterals from '@babel/plugin-transform-template-literals';
import TransformModules from '@babel/plugin-transform-modules-amd';
import TransformUnicodeEscapes from '@babel/plugin-transform-unicode-escapes';
// @ts-expect-error no upstream types
import TransformTypescript from '@babel/plugin-transform-typescript';
import { stripIndent } from 'common-tags';
import { EmberTemplateCompiler } from '../src/ember-template-compiler';
import sinon from 'sinon';
Expand Down Expand Up @@ -1780,6 +1782,76 @@ describe('htmlbars-inline-precompile', function () {
);
`);
});

it('interoperates correctly with @babel/plugin-transform-typescript when handling locals with hbs target', function () {
plugins = [
[
HTMLBarsInlinePrecompile,
{
compiler,
targetFormat: 'hbs',
},
],
TransformTypescript,
];

let transformed = transform(
`import { template } from '@ember/template-compiler';
import HelloWorld from 'somewhere';
export default template('<HelloWorld />', { eval: function() { return eval(arguments[0]) } })
`
);

expect(transformed).toEqualCode(`
import HelloWorld from "somewhere";
import { precompileTemplate } from "@ember/template-compilation";
import { setComponentTemplate } from "@ember/component";
import templateOnly from "@ember/component/template-only";
export default setComponentTemplate(precompileTemplate('<HelloWorld />', { scope: () => ({ HelloWorld }), strictMode: true }), templateOnly());
`);
});

it('interoperates correctly with @babel/plugin-transform-typescript when handling locals with wire target', function () {
plugins = [
[
HTMLBarsInlinePrecompile,
{
compiler,
targetFormat: 'wire',
},
],
TransformTypescript,
];

let transformed = transform(
`import { template } from '@ember/template-compiler';
import HelloWorld from 'somewhere';
export default template('<HelloWorld />', { eval: function() { return eval(arguments[0]) } })
`
);

expect(normalizeWireFormat(transformed)).toEqualCode(`
import HelloWorld from 'somewhere';
import { createTemplateFactory } from "@ember/template-factory";
import { setComponentTemplate } from "@ember/component";
import templateOnly from "@ember/component/template-only";
export default setComponentTemplate(
createTemplateFactory(
/*
<HelloWorld />
*/
{
id: "<id>",
block: "[[[8,[32,0],null,null,null]],[],false,[]]",
moduleName: "<moduleName>",
scope: () => [HelloWorld],
isStrictMode: true,
}
),
templateOnly()
);
`);
});
});

describe('content-tag end-to-end', function () {
Expand Down
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,19 @@
"@babel/plugin-proposal-class-properties": "^7.14.5",
"@babel/plugin-transform-modules-amd": "^7.14.5",
"@babel/plugin-transform-template-literals": "^7.14.5",
"@babel/plugin-transform-typescript": "^7.22.11",
"@babel/plugin-transform-unicode-escapes": "^7.14.5",
"@babel/traverse": "^7.14.5",
"content-tag": "^0.1.0",
"@types/babel__core": "^7.20.1",
"@types/babel__traverse": "^7.11.1",
"@types/jest": "^29.2.3",
"@types/node": "^20.5.7",
"@types/sinon": "^10.0.13",
"@typescript-eslint/eslint-plugin": "^4.28.4",
"@typescript-eslint/parser": "^4.28.4",
"code-equality-assertions": "^0.7.0",
"common-tags": "^1.8.0",
"content-tag": "^0.1.0",
"ember-source": "^3.28.9",
"eslint": "^6.8.0",
"eslint-config-prettier": "^6.15.0",
Expand Down
Loading