Skip to content

Commit 69a0e76

Browse files
committed
Remove ember-template-imports in favor of content-tag
1 parent d6efc35 commit 69a0e76

File tree

3 files changed

+47
-14
lines changed

3 files changed

+47
-14
lines changed

packages/environment-ember-template-imports/-private/environment/preprocess.ts

+37-10
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,53 @@
11
import { GlintExtensionPreprocess } from '@glint/core/config-types';
2-
import { parseTemplates } from 'ember-template-imports';
32
import { GLOBAL_TAG, PreprocessData, TemplateLocation } from './common';
4-
3+
/**
4+
* We don't need to actually generate the code that would be emitted for
5+
* a real app to build, we can use placeholders, so we have less offsets
6+
* to worry about (precompile, setComponentTemplate, their imports, etc)
7+
*/
58
const TEMPLATE_START = `[${GLOBAL_TAG}\``;
69
const TEMPLATE_END = '`]';
710

11+
// NOTE: This import is a lie -- We are not real ESM, and this is compiled to CJS.
12+
// ESM usage would be different here, and this is the CJS version of content-tag.
13+
import { Preprocessor } from 'content-tag';
14+
const p = new Preprocessor();
15+
16+
interface Parsed {
17+
type: 'expression' | 'class-member';
18+
tagName: 'template';
19+
contents: string;
20+
range: {
21+
start: number;
22+
end: number;
23+
};
24+
contentRange: {
25+
start: number;
26+
end: number;
27+
};
28+
startRange: {
29+
end: number;
30+
start: number;
31+
};
32+
endRange: {
33+
start: number;
34+
end: number;
35+
};
36+
}
37+
838
export const preprocess: GlintExtensionPreprocess<PreprocessData> = (source, path) => {
9-
let templates = parseTemplates(source, path, { templateTag: 'template' }).filter(
10-
(match) => match.type === 'template-tag'
11-
);
39+
let templates = p.parse(source, path) as Parsed[];
1240

1341
let templateLocations: Array<TemplateLocation> = [];
1442
let segments: Array<string> = [];
1543
let sourceOffset = 0;
1644
let delta = 0;
1745

1846
for (let template of templates) {
19-
let { start, end } = template;
20-
let startTagLength = template.start[0].length;
21-
let endTagLength = template.end[0].length;
22-
let startTagOffset = start.index ?? -1;
23-
let endTagOffset = end.index ?? -1;
47+
let startTagLength = template.startRange.end - template.startRange.start;
48+
let endTagLength = template.endRange.end - template.endRange.start;
49+
let startTagOffset = template.startRange.start;
50+
let endTagOffset = template.endRange.start;
2451

2552
if (startTagOffset === -1 || endTagOffset === -1) continue;
2653

packages/environment-ember-template-imports/package.json

+4-3
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,16 @@
2626
"-private/**/*.{js,d.ts}",
2727
"globals/index.d.ts"
2828
],
29+
"dependencies": {
30+
"content-tag": "^1.1.0"
31+
},
2932
"peerDependencies": {
3033
"@glint/environment-ember-loose": "^1.2.0",
3134
"@glint/template": "^1.2.0",
3235
"@types/ember__component": "^4.0.10",
3336
"@types/ember__helper": "^4.0.1",
3437
"@types/ember__modifier": "^4.0.3",
35-
"@types/ember__routing": "^4.0.12",
36-
"ember-template-imports": "^3.0.0"
38+
"@types/ember__routing": "^4.0.12"
3739
},
3840
"peerDependenciesMeta": {
3941
"@types/ember__component": {
@@ -55,7 +57,6 @@
5557
"@types/ember__helper": "^4.0.1",
5658
"@types/ember__modifier": "^4.0.3",
5759
"@types/ember__routing": "^4.0.12",
58-
"ember-template-imports": "^3.0.0",
5960
"vitest": "^0.22.0"
6061
},
6162
"publishConfig": {

yarn.lock

+6-1
Original file line numberDiff line numberDiff line change
@@ -5156,6 +5156,11 @@ [email protected]:
51565156
dependencies:
51575157
safe-buffer "5.2.1"
51585158

5159+
content-tag@^1.1.0:
5160+
version "1.1.0"
5161+
resolved "https://registry.yarnpkg.com/content-tag/-/content-tag-1.1.0.tgz#fcef4bdcf1850f9b67bf0b6f7aee217c6d7ea9fa"
5162+
integrity sha512-bktivDORs9M890KwVKrIONYvHhwshfgF4b1G/TFPrjH12Ag2GDiSdxVHqIzMxWZ297VgIRPSImURlpcOzJP/LQ==
5163+
51595164
content-type@~1.0.4:
51605165
version "1.0.4"
51615166
resolved "https://registry.yarnpkg.com/content-type/-/content-type-1.0.4.tgz#e138cc75e040c727b1966fe5e5f8c9aee256fe3b"
@@ -6466,7 +6471,7 @@ ember-template-imports@^1.1.1:
64666471
ember-cli-version-checker "^5.1.2"
64676472
validate-peer-dependencies "^1.1.0"
64686473

6469-
ember-template-imports@^3.0.0, ember-template-imports@^3.1.1:
6474+
ember-template-imports@^3.1.1:
64706475
version "3.4.0"
64716476
resolved "https://registry.yarnpkg.com/ember-template-imports/-/ember-template-imports-3.4.0.tgz#c40757e2d41e289ce08c0fe80671000bf216e0ef"
64726477
integrity sha512-3Cwcj3NXA129g3ZhmrQ/nYOxksFonTmB/qxyaSNTHrLBSoc93UZys47hBz13DlcfoeSCCrNt2Qpq1j890I04PQ==

0 commit comments

Comments
 (0)