Skip to content

Commit 7c112ff

Browse files
authored
Merge pull request #28 from emberjs/dont-require-compiler
Don't require compiler when targetFormat='hbs'
2 parents 6f8e3fe + 1cb7a9e commit 7c112ff

File tree

4 files changed

+98
-116
lines changed

4 files changed

+98
-116
lines changed

__tests__/tests.ts

+21-78
Original file line numberDiff line numberDiff line change
@@ -630,10 +630,7 @@ describe('htmlbars-inline-precompile', function () {
630630

631631
it('allows AST transform to bind a JS expression', function () {
632632
plugins = [
633-
[
634-
HTMLBarsInlinePrecompile,
635-
{ compiler, targetFormat: 'hbs', transforms: [expressionTransform] },
636-
],
633+
[HTMLBarsInlinePrecompile, { targetFormat: 'hbs', transforms: [expressionTransform] }],
637634
];
638635

639636
let transformed = transform(stripIndent`
@@ -671,9 +668,7 @@ describe('htmlbars-inline-precompile', function () {
671668
});
672669

673670
it('allows AST transform to bind a JS import', function () {
674-
plugins = [
675-
[HTMLBarsInlinePrecompile, { compiler, targetFormat: 'hbs', transforms: [importTransform] }],
676-
];
671+
plugins = [[HTMLBarsInlinePrecompile, { targetFormat: 'hbs', transforms: [importTransform] }]];
677672

678673
let transformed = transform(stripIndent`
679674
import { precompileTemplate } from '@ember/template-compilation';
@@ -692,9 +687,7 @@ describe('htmlbars-inline-precompile', function () {
692687
});
693688

694689
it('does not smash existing js binding for import', function () {
695-
plugins = [
696-
[HTMLBarsInlinePrecompile, { compiler, targetFormat: 'hbs', transforms: [importTransform] }],
697-
];
690+
plugins = [[HTMLBarsInlinePrecompile, { targetFormat: 'hbs', transforms: [importTransform] }]];
698691

699692
let transformed = transform(stripIndent`
700693
import { precompileTemplate } from '@ember/template-compilation';
@@ -719,9 +712,7 @@ describe('htmlbars-inline-precompile', function () {
719712
});
720713

721714
it('does not smash existing hbs binding for import', function () {
722-
plugins = [
723-
[HTMLBarsInlinePrecompile, { compiler, targetFormat: 'hbs', transforms: [importTransform] }],
724-
];
715+
plugins = [[HTMLBarsInlinePrecompile, { targetFormat: 'hbs', transforms: [importTransform] }]];
725716

726717
let transformed = transform(stripIndent`
727718
import { precompileTemplate } from '@ember/template-compilation';
@@ -746,10 +737,7 @@ describe('htmlbars-inline-precompile', function () {
746737

747738
it('does not smash existing js binding for expression', function () {
748739
plugins = [
749-
[
750-
HTMLBarsInlinePrecompile,
751-
{ compiler, targetFormat: 'hbs', transforms: [expressionTransform] },
752-
],
740+
[HTMLBarsInlinePrecompile, { targetFormat: 'hbs', transforms: [expressionTransform] }],
753741
];
754742

755743
let transformed = transform(stripIndent`
@@ -775,9 +763,7 @@ describe('htmlbars-inline-precompile', function () {
775763
});
776764

777765
it('reuses existing imports when possible', () => {
778-
plugins = [
779-
[HTMLBarsInlinePrecompile, { compiler, targetFormat: 'hbs', transforms: [importTransform] }],
780-
];
766+
plugins = [[HTMLBarsInlinePrecompile, { targetFormat: 'hbs', transforms: [importTransform] }]];
781767

782768
let transformed = transform(stripIndent`
783769
import { precompileTemplate } from '@ember/template-compilation';
@@ -794,9 +780,7 @@ describe('htmlbars-inline-precompile', function () {
794780
});
795781

796782
it('rebinds existing imports when necessary', () => {
797-
plugins = [
798-
[HTMLBarsInlinePrecompile, { compiler, targetFormat: 'hbs', transforms: [importTransform] }],
799-
];
783+
plugins = [[HTMLBarsInlinePrecompile, { targetFormat: 'hbs', transforms: [importTransform] }]];
800784

801785
let transformed = transform(stripIndent`
802786
import { precompileTemplate } from '@ember/template-compilation';
@@ -817,10 +801,7 @@ describe('htmlbars-inline-precompile', function () {
817801

818802
it('does not smash own newly-created js binding for expression', function () {
819803
plugins = [
820-
[
821-
HTMLBarsInlinePrecompile,
822-
{ compiler, targetFormat: 'hbs', transforms: [expressionTransform] },
823-
],
804+
[HTMLBarsInlinePrecompile, { targetFormat: 'hbs', transforms: [expressionTransform] }],
824805
];
825806

826807
let transformed = transform(stripIndent`
@@ -852,10 +833,7 @@ describe('htmlbars-inline-precompile', function () {
852833

853834
it('does not smash existing hbs block binding for expression', function () {
854835
plugins = [
855-
[
856-
HTMLBarsInlinePrecompile,
857-
{ compiler, targetFormat: 'hbs', transforms: [expressionTransform] },
858-
],
836+
[HTMLBarsInlinePrecompile, { targetFormat: 'hbs', transforms: [expressionTransform] }],
859837
];
860838

861839
let transformed = transform(stripIndent`
@@ -880,10 +858,7 @@ describe('htmlbars-inline-precompile', function () {
880858

881859
it('does not smash existing hbs element binding for expression', function () {
882860
plugins = [
883-
[
884-
HTMLBarsInlinePrecompile,
885-
{ compiler, targetFormat: 'hbs', transforms: [expressionTransform] },
886-
],
861+
[HTMLBarsInlinePrecompile, { targetFormat: 'hbs', transforms: [expressionTransform] }],
887862
];
888863

889864
let transformed = transform(stripIndent`
@@ -908,10 +883,7 @@ describe('htmlbars-inline-precompile', function () {
908883

909884
it('understands that block params are only defined in the body, not the arguments, of an element', function () {
910885
plugins = [
911-
[
912-
HTMLBarsInlinePrecompile,
913-
{ compiler, targetFormat: 'hbs', transforms: [expressionTransform] },
914-
],
886+
[HTMLBarsInlinePrecompile, { targetFormat: 'hbs', transforms: [expressionTransform] }],
915887
];
916888

917889
let transformed = transform(stripIndent`
@@ -936,10 +908,7 @@ describe('htmlbars-inline-precompile', function () {
936908

937909
it('does not smash other previously-bound expressions with new ones', () => {
938910
plugins = [
939-
[
940-
HTMLBarsInlinePrecompile,
941-
{ compiler, targetFormat: 'hbs', transforms: [expressionTransform] },
942-
],
911+
[HTMLBarsInlinePrecompile, { targetFormat: 'hbs', transforms: [expressionTransform] }],
943912
];
944913

945914
let transformed = transform(stripIndent`
@@ -981,9 +950,7 @@ describe('htmlbars-inline-precompile', function () {
981950
};
982951
};
983952

984-
plugins = [
985-
[HTMLBarsInlinePrecompile, { compiler, targetFormat: 'hbs', transforms: [nowTransform] }],
986-
];
953+
plugins = [[HTMLBarsInlinePrecompile, { targetFormat: 'hbs', transforms: [nowTransform] }]];
987954

988955
let transformed = transform(stripIndent`
989956
import { precompileTemplate } from '@ember/template-compilation';
@@ -1014,9 +981,7 @@ describe('htmlbars-inline-precompile', function () {
1014981
};
1015982
};
1016983

1017-
plugins = [
1018-
[HTMLBarsInlinePrecompile, { compiler, targetFormat: 'hbs', transforms: [compatTransform] }],
1019-
];
984+
plugins = [[HTMLBarsInlinePrecompile, { targetFormat: 'hbs', transforms: [compatTransform] }]];
1020985

1021986
let transformed = transform(stripIndent`
1022987
import { precompileTemplate } from '@ember/template-compilation';
@@ -1043,9 +1008,7 @@ describe('htmlbars-inline-precompile', function () {
10431008
};
10441009
};
10451010

1046-
plugins = [
1047-
[HTMLBarsInlinePrecompile, { compiler, targetFormat: 'hbs', transforms: [compatTransform] }],
1048-
];
1011+
plugins = [[HTMLBarsInlinePrecompile, { targetFormat: 'hbs', transforms: [compatTransform] }]];
10491012

10501013
let transformed = transform(stripIndent`
10511014
import { precompileTemplate } from '@ember/template-compilation';
@@ -1073,9 +1036,7 @@ describe('htmlbars-inline-precompile', function () {
10731036
};
10741037

10751038
it('can run an ast transform inside precompileTemplate', function () {
1076-
plugins = [
1077-
[HTMLBarsInlinePrecompile, { compiler, targetFormat: 'hbs', transforms: [color] }],
1078-
];
1039+
plugins = [[HTMLBarsInlinePrecompile, { targetFormat: 'hbs', transforms: [color] }]];
10791040

10801041
let transformed = transform(stripIndent`
10811042
import { precompileTemplate } from '@ember/template-compilation';
@@ -1113,10 +1074,7 @@ describe('htmlbars-inline-precompile', function () {
11131074

11141075
it('can create the options object for precompileTemplate', function () {
11151076
plugins = [
1116-
[
1117-
HTMLBarsInlinePrecompile,
1118-
{ compiler, targetFormat: 'hbs', transforms: [expressionTransform] },
1119-
],
1077+
[HTMLBarsInlinePrecompile, { targetFormat: 'hbs', transforms: [expressionTransform] }],
11201078
];
11211079

11221080
let transformed = transform(stripIndent`
@@ -1137,10 +1095,7 @@ describe('htmlbars-inline-precompile', function () {
11371095

11381096
it('adds scope to existing options object', function () {
11391097
plugins = [
1140-
[
1141-
HTMLBarsInlinePrecompile,
1142-
{ compiler, targetFormat: 'hbs', transforms: [expressionTransform] },
1143-
],
1098+
[HTMLBarsInlinePrecompile, { targetFormat: 'hbs', transforms: [expressionTransform] }],
11441099
];
11451100

11461101
let transformed = transform(stripIndent`
@@ -1166,10 +1121,7 @@ describe('htmlbars-inline-precompile', function () {
11661121

11671122
it('adds new locals to preexisting scope', function () {
11681123
plugins = [
1169-
[
1170-
HTMLBarsInlinePrecompile,
1171-
{ compiler, targetFormat: 'hbs', transforms: [expressionTransform] },
1172-
],
1124+
[HTMLBarsInlinePrecompile, { targetFormat: 'hbs', transforms: [expressionTransform] }],
11731125
];
11741126

11751127
let transformed = transform(stripIndent`
@@ -1197,10 +1149,7 @@ describe('htmlbars-inline-precompile', function () {
11971149

11981150
it('adds new locals to preexisting renamed scope', function () {
11991151
plugins = [
1200-
[
1201-
HTMLBarsInlinePrecompile,
1202-
{ compiler, targetFormat: 'hbs', transforms: [expressionTransform] },
1203-
],
1152+
[HTMLBarsInlinePrecompile, { targetFormat: 'hbs', transforms: [expressionTransform] }],
12041153
];
12051154

12061155
let transformed = transform(stripIndent`
@@ -1292,7 +1241,6 @@ describe('htmlbars-inline-precompile', function () {
12921241
[
12931242
HTMLBarsInlinePrecompile,
12941243
{
1295-
compiler,
12961244
targetFormat: 'hbs',
12971245
transforms: [expressionTransform],
12981246
enableLegacyModules: ['ember-cli-htmlbars'],
@@ -1318,7 +1266,7 @@ describe('htmlbars-inline-precompile', function () {
13181266
});
13191267

13201268
it('leaves html entities unchanged when there are no transforms', function () {
1321-
plugins = [[HTMLBarsInlinePrecompile, { compiler, targetFormat: 'hbs', transforms: [] }]];
1269+
plugins = [[HTMLBarsInlinePrecompile, { targetFormat: 'hbs', transforms: [] }]];
13221270

13231271
let transformed = transform(stripIndent`
13241272
import { precompileTemplate } from '@ember/template-compilation';
@@ -1336,7 +1284,6 @@ describe('htmlbars-inline-precompile', function () {
13361284
[
13371285
HTMLBarsInlinePrecompile,
13381286
{
1339-
compiler,
13401287
targetFormat: 'hbs',
13411288
transforms: [color],
13421289
},
@@ -1363,7 +1310,6 @@ describe('htmlbars-inline-precompile', function () {
13631310
[
13641311
HTMLBarsInlinePrecompile,
13651312
{
1366-
compiler,
13671313
targetFormat: 'hbs',
13681314
transforms: [color],
13691315
},
@@ -1402,7 +1348,6 @@ describe('htmlbars-inline-precompile', function () {
14021348
[
14031349
HTMLBarsInlinePrecompile,
14041350
{
1405-
compiler,
14061351
targetFormat: 'hbs',
14071352
transforms: [color],
14081353
},
@@ -1437,7 +1382,6 @@ describe('htmlbars-inline-precompile', function () {
14371382
[
14381383
HTMLBarsInlinePrecompile,
14391384
{
1440-
compiler,
14411385
targetFormat: 'hbs',
14421386
transforms: [],
14431387
},
@@ -1465,7 +1409,6 @@ describe('htmlbars-inline-precompile', function () {
14651409
[
14661410
HTMLBarsInlinePrecompile,
14671411
{
1468-
compiler,
14691412
targetFormat: 'hbs',
14701413
transforms: [expressionTransform],
14711414
enableLegacyModules: ['ember-cli-htmlbars'],

src/ember-template-compiler.ts

+2-15
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import { ASTv1 } from '@glimmer/syntax';
2-
import { ExtendedPluginBuilder } from './js-utils';
1+
import { ASTv1, PreprocessOptions } from '@glimmer/syntax';
32

43
// The interface we use from ember-template-compiler.js
54
export interface EmberTemplateCompiler {
@@ -9,19 +8,7 @@ export interface EmberTemplateCompiler {
98
_preprocess(src: string, options?: PreprocessOptions): ASTv1.Template;
109
}
1110

12-
export interface PreprocessOptions {
13-
contents: string;
14-
moduleName: string;
15-
plugins?: { ast?: ExtendedPluginBuilder[] };
16-
filename?: string;
17-
parseOptions?: {
18-
srcName?: string;
19-
ignoreStandalone?: boolean;
20-
};
21-
mode?: 'codemod' | 'precompile';
22-
strictMode?: boolean;
23-
locals?: string[];
24-
}
11+
export { PreprocessOptions };
2512

2613
export function assertTemplateCompiler(
2714
emberTemplateCompiler: any

src/node-main.ts

+1-3
Original file line numberDiff line numberDiff line change
@@ -34,16 +34,14 @@ function cwdRequire(moduleName: string) {
3434
}
3535

3636
function handleNodeSpecificOptions(opts: Options): SharedOptions {
37-
let compiler: EmberTemplateCompiler;
37+
let compiler: EmberTemplateCompiler | undefined = undefined;
3838
if (opts.compilerPath) {
3939
let mod: any = cwdRequire(opts.compilerPath);
4040
assertTemplateCompiler(mod);
4141
compiler = mod;
4242
} else if (opts.compiler) {
4343
assertTemplateCompiler(opts.compiler);
4444
compiler = opts.compiler;
45-
} else {
46-
throw new Error(`must provide compilerPath or compiler`);
4745
}
4846

4947
let transforms = [];

0 commit comments

Comments
 (0)