Skip to content

Commit 1cb7a9e

Browse files
committed
better type adjustments
1 parent 9ee067e commit 1cb7a9e

File tree

2 files changed

+11
-19
lines changed

2 files changed

+11
-19
lines changed

Diff for: 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

Diff for: src/plugin.ts

+9-4
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { JSUtils, ExtendedPluginBuilder } from './js-utils';
77
import type { EmberTemplateCompiler, PreprocessOptions } from './ember-template-compiler';
88
import { LegacyModuleName } from './public-types';
99
import { ScopeLocals } from './scope-locals';
10-
import { getTemplateLocals, preprocess, print } from '@glimmer/syntax';
10+
import { ASTPluginBuilder, getTemplateLocals, preprocess, print } from '@glimmer/syntax';
1111

1212
export * from './public-types';
1313

@@ -395,7 +395,10 @@ function buildPrecompileOptions<EnvSpecificOptions>(
395395

396396
let output: PreprocessOptions & Record<string, unknown> = {
397397
contents: template,
398-
meta,
398+
399+
// we've extended meta to add jsutils, but the types in @glimmer/syntax
400+
// don't account for extension
401+
meta: meta as PreprocessOptions['meta'],
399402

400403
// TODO: embroider's template-compiler allows this to be overriden to get
401404
// backward-compatible module names that don't match the real name of the
@@ -408,7 +411,9 @@ function buildPrecompileOptions<EnvSpecificOptions>(
408411
filename: state.filename,
409412

410413
plugins: {
411-
ast: state.normalizedOpts.transforms,
414+
// the cast is needed here only because our meta is extended. That is,
415+
// these plugins can access meta.jsutils.
416+
ast: state.normalizedOpts.transforms as ASTPluginBuilder[],
412417
},
413418
};
414419

@@ -544,7 +549,7 @@ function insertTransformedTemplate<EnvSpecificOptions>(
544549
formatOptions,
545550
scopeLocals
546551
);
547-
let ast = preprocess(template, { ...options, mode: 'codemod' } as any);
552+
let ast = preprocess(template, { ...options, mode: 'codemod' });
548553
let transformed = print(ast, { entityEncoding: 'raw' });
549554
if (target.isCallExpression()) {
550555
(target.get('arguments.0') as NodePath<t.Node>).replaceWith(t.stringLiteral(transformed));

0 commit comments

Comments
 (0)