@glint/ember-tsc 1.3.0 → 1.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/environment-ember-template-imports/-private/environment/preprocess.d.ts.map +1 -1
- package/lib/environment-ember-template-imports/-private/environment/preprocess.js +21 -52
- package/lib/environment-ember-template-imports/-private/environment/preprocess.js.map +1 -1
- package/package.json +2 -2
- package/src/environment-ember-template-imports/-private/environment/preprocess.ts +21 -59
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"preprocess.d.ts","sourceRoot":"","sources":["../../../../src/environment-ember-template-imports/-private/environment/preprocess.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,wBAAwB,EAAE,MAAM,+BAA+B,CAAC;AACzE,OAAO,EAAc,cAAc,EAAoB,MAAM,aAAa,CAAC;AAQ3E,eAAO,MAAM,UAAU,EAAE,wBAAwB,CAAC,cAAc,
|
|
1
|
+
{"version":3,"file":"preprocess.d.ts","sourceRoot":"","sources":["../../../../src/environment-ember-template-imports/-private/environment/preprocess.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,wBAAwB,EAAE,MAAM,+BAA+B,CAAC;AACzE,OAAO,EAAc,cAAc,EAAoB,MAAM,aAAa,CAAC;AAQ3E,eAAO,MAAM,UAAU,EAAE,wBAAwB,CAAC,cAAc,CA0C/D,CAAC"}
|
|
@@ -4,52 +4,34 @@ const TEMPLATE_END = '`]';
|
|
|
4
4
|
import { Preprocessor } from 'content-tag';
|
|
5
5
|
const p = new Preprocessor();
|
|
6
6
|
export const preprocess = (source, path) => {
|
|
7
|
-
// NOTE: https://github.com/embroider-build/content-tag/issues/45
|
|
8
|
-
// All indicies are byte-index, not char-index.
|
|
9
7
|
let templates = p.parse(source, { filename: path });
|
|
10
8
|
let templateLocations = [];
|
|
11
9
|
let contents = '';
|
|
12
|
-
let
|
|
13
|
-
let deltaBytes = 0;
|
|
14
|
-
let sourceBuffer = getBuffer(source);
|
|
10
|
+
let sourceOffset = 0;
|
|
15
11
|
for (let template of templates) {
|
|
16
|
-
let
|
|
17
|
-
let
|
|
18
|
-
let
|
|
19
|
-
let
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
let
|
|
28
|
-
|
|
29
|
-
contents = contents.concat(TEMPLATE_START);
|
|
30
|
-
// For TEMPLATE_START & TEMPLATE_END, characters === bytes
|
|
31
|
-
deltaBytes += startTagLengthBytes - TEMPLATE_START.length;
|
|
32
|
-
let transformedEnd = endTagOffsetBytes - deltaBytes + TEMPLATE_END.length;
|
|
33
|
-
let templateContentSegment = sourceBuffer.subarray(startTagOffsetBytes + startTagLengthBytes, endTagOffsetBytes);
|
|
34
|
-
let templateContentSegmentString = templateContentSegment.toString();
|
|
35
|
-
let escapedTemplateContentSegment = templateContentSegmentString
|
|
36
|
-
.replaceAll('${{', '\\${{')
|
|
37
|
-
.replaceAll('`', '\\`');
|
|
38
|
-
deltaBytes += templateContentSegmentString.length - escapedTemplateContentSegment.length;
|
|
39
|
-
contents = contents.concat(escapedTemplateContentSegment);
|
|
40
|
-
contents = contents.concat(TEMPLATE_END);
|
|
41
|
-
deltaBytes += endTagLengthBytes - TEMPLATE_END.length;
|
|
42
|
-
sourceOffsetBytes = endTagOffsetBytes + endTagLengthBytes;
|
|
12
|
+
let startTagOffset = template.startRange.startUtf16Codepoint;
|
|
13
|
+
let startTagEnd = template.startRange.endUtf16Codepoint;
|
|
14
|
+
let endTagOffset = template.endRange.startUtf16Codepoint;
|
|
15
|
+
let endTagEnd = template.endRange.endUtf16Codepoint;
|
|
16
|
+
contents += source.slice(sourceOffset, startTagOffset);
|
|
17
|
+
let transformedStart = contents.length;
|
|
18
|
+
contents += TEMPLATE_START;
|
|
19
|
+
let templateContent = source.slice(startTagEnd, endTagOffset);
|
|
20
|
+
let escapedContent = templateContent.replaceAll('${{', '\\${{').replaceAll('`', '\\`');
|
|
21
|
+
contents += escapedContent;
|
|
22
|
+
contents += TEMPLATE_END;
|
|
23
|
+
let transformedEnd = contents.length;
|
|
24
|
+
sourceOffset = endTagEnd;
|
|
43
25
|
templateLocations.push({
|
|
44
|
-
startTagOffset
|
|
45
|
-
endTagOffset
|
|
46
|
-
startTagLength:
|
|
47
|
-
endTagLength:
|
|
48
|
-
transformedStart
|
|
49
|
-
transformedEnd
|
|
26
|
+
startTagOffset,
|
|
27
|
+
endTagOffset,
|
|
28
|
+
startTagLength: startTagEnd - startTagOffset,
|
|
29
|
+
endTagLength: endTagEnd - endTagOffset,
|
|
30
|
+
transformedStart,
|
|
31
|
+
transformedEnd,
|
|
50
32
|
});
|
|
51
33
|
}
|
|
52
|
-
contents
|
|
34
|
+
contents += source.slice(sourceOffset);
|
|
53
35
|
return {
|
|
54
36
|
contents,
|
|
55
37
|
data: {
|
|
@@ -57,17 +39,4 @@ export const preprocess = (source, path) => {
|
|
|
57
39
|
},
|
|
58
40
|
};
|
|
59
41
|
};
|
|
60
|
-
function byteToCharIndex(str, byteOffset) {
|
|
61
|
-
const buf = getBuffer(str);
|
|
62
|
-
return buf.subarray(0, byteOffset).toString().length;
|
|
63
|
-
}
|
|
64
|
-
const BufferMap = new Map();
|
|
65
|
-
function getBuffer(str) {
|
|
66
|
-
let buf = BufferMap.get(str);
|
|
67
|
-
if (!buf) {
|
|
68
|
-
buf = Buffer.from(str);
|
|
69
|
-
BufferMap.set(str, buf);
|
|
70
|
-
}
|
|
71
|
-
return buf;
|
|
72
|
-
}
|
|
73
42
|
//# sourceMappingURL=preprocess.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"preprocess.js","sourceRoot":"","sources":["../../../../src/environment-ember-template-imports/-private/environment/preprocess.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAoC,MAAM,aAAa,CAAC;AAE3E,MAAM,cAAc,GAAG,IAAI,UAAU,IAAI,CAAC;AAC1C,MAAM,YAAY,GAAG,IAA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,CAAC,MAAM,CAAC;QACvC,QAAQ,IAAI,cAAc,CAAC;QAE3B,IAAI,eAAe,GAAG,MAAM,CAAC,KAAK,CAAC,WAAW,EAAE,YAAY,CAAC,CAAC;QAC9D,IAAI,cAAc,GAAG,eAAe,CAAC,UAAU,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC,UAAU,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;QACvF,QAAQ,IAAI,cAAc,CAAC;QAC3B,QAAQ,IAAI,YAAY,CAAC;QACzB,IAAI,cAAc,GAAG,QAAQ,CAAC,MAAM,CAAC;QAErC,YAAY,GAAG,SAAS,CAAC;QACzB,iBAAiB,CAAC,IAAI,CAAC;YACrB,cAAc;YACd,YAAY;YACZ,cAAc,EAAE,WAAW,GAAG,cAAc;YAC5C,YAAY,EAAE,SAAS,GAAG,YAAY;YACtC,gBAAgB;YAChB,cAAc;SACf,CAAC,CAAC;IACL,CAAC;IAED,QAAQ,IAAI,MAAM,CAAC,KAAK,CAAC,YAAY,CAAC,CAAC;IACvC,OAAO;QACL,QAAQ;QACR,IAAI,EAAE;YACJ,iBAAiB;SAClB;KACF,CAAC;AACJ,CAAC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@glint/ember-tsc",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.4.0",
|
|
4
4
|
"repository": "typed-ember/glint",
|
|
5
5
|
"description": "A CLI for performing typechecking on Glimmer templates",
|
|
6
6
|
"license": "MIT",
|
|
@@ -64,7 +64,7 @@
|
|
|
64
64
|
"@volar/source-map": "~2.4.28",
|
|
65
65
|
"@volar/test-utils": "~2.4.28",
|
|
66
66
|
"@volar/typescript": "~2.4.28",
|
|
67
|
-
"content-tag": "^
|
|
67
|
+
"content-tag": "^4.1.1",
|
|
68
68
|
"silent-error": "^1.1.1",
|
|
69
69
|
"volar-service-html": "~0.0.68",
|
|
70
70
|
"volar-service-typescript": "~0.0.68",
|
|
@@ -8,63 +8,41 @@ import { Preprocessor } from 'content-tag';
|
|
|
8
8
|
const p = new Preprocessor();
|
|
9
9
|
|
|
10
10
|
export const preprocess: GlintExtensionPreprocess<PreprocessData> = (source, path) => {
|
|
11
|
-
// NOTE: https://github.com/embroider-build/content-tag/issues/45
|
|
12
|
-
// All indicies are byte-index, not char-index.
|
|
13
11
|
let templates = p.parse(source, { filename: path });
|
|
14
12
|
|
|
15
13
|
let templateLocations: Array<TemplateLocation> = [];
|
|
16
14
|
let contents = '';
|
|
17
|
-
let
|
|
18
|
-
let deltaBytes = 0;
|
|
19
|
-
|
|
20
|
-
let sourceBuffer = getBuffer(source);
|
|
15
|
+
let sourceOffset = 0;
|
|
21
16
|
|
|
22
17
|
for (let template of templates) {
|
|
23
|
-
let
|
|
24
|
-
let
|
|
25
|
-
let
|
|
26
|
-
let
|
|
27
|
-
let transformedStartBytes = startTagOffsetBytes - deltaBytes;
|
|
28
|
-
/**
|
|
29
|
-
* TODO: we want content-tag to manage all this for us, as managing indicies
|
|
30
|
-
* can be error-prone.
|
|
31
|
-
*
|
|
32
|
-
* SEE: https://github.com/embroider-build/content-tag/issues/39#issuecomment-1832443310
|
|
33
|
-
*/
|
|
34
|
-
let prefixingSegment = sourceBuffer.subarray(sourceOffsetBytes, startTagOffsetBytes);
|
|
35
|
-
contents = contents.concat(prefixingSegment.toString());
|
|
36
|
-
contents = contents.concat(TEMPLATE_START);
|
|
18
|
+
let startTagOffset = template.startRange.startUtf16Codepoint;
|
|
19
|
+
let startTagEnd = template.startRange.endUtf16Codepoint;
|
|
20
|
+
let endTagOffset = template.endRange.startUtf16Codepoint;
|
|
21
|
+
let endTagEnd = template.endRange.endUtf16Codepoint;
|
|
37
22
|
|
|
38
|
-
|
|
39
|
-
deltaBytes += startTagLengthBytes - TEMPLATE_START.length;
|
|
23
|
+
contents += source.slice(sourceOffset, startTagOffset);
|
|
40
24
|
|
|
41
|
-
let
|
|
42
|
-
|
|
43
|
-
startTagOffsetBytes + startTagLengthBytes,
|
|
44
|
-
endTagOffsetBytes,
|
|
45
|
-
);
|
|
46
|
-
let templateContentSegmentString = templateContentSegment.toString();
|
|
47
|
-
let escapedTemplateContentSegment = templateContentSegmentString
|
|
48
|
-
.replaceAll('${{', '\\${{')
|
|
49
|
-
.replaceAll('`', '\\`');
|
|
50
|
-
deltaBytes += templateContentSegmentString.length - escapedTemplateContentSegment.length;
|
|
25
|
+
let transformedStart = contents.length;
|
|
26
|
+
contents += TEMPLATE_START;
|
|
51
27
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
28
|
+
let templateContent = source.slice(startTagEnd, endTagOffset);
|
|
29
|
+
let escapedContent = templateContent.replaceAll('${{', '\\${{').replaceAll('`', '\\`');
|
|
30
|
+
contents += escapedContent;
|
|
31
|
+
contents += TEMPLATE_END;
|
|
32
|
+
let transformedEnd = contents.length;
|
|
55
33
|
|
|
56
|
-
|
|
34
|
+
sourceOffset = endTagEnd;
|
|
57
35
|
templateLocations.push({
|
|
58
|
-
startTagOffset
|
|
59
|
-
endTagOffset
|
|
60
|
-
startTagLength:
|
|
61
|
-
endTagLength:
|
|
62
|
-
transformedStart
|
|
63
|
-
transformedEnd
|
|
36
|
+
startTagOffset,
|
|
37
|
+
endTagOffset,
|
|
38
|
+
startTagLength: startTagEnd - startTagOffset,
|
|
39
|
+
endTagLength: endTagEnd - endTagOffset,
|
|
40
|
+
transformedStart,
|
|
41
|
+
transformedEnd,
|
|
64
42
|
});
|
|
65
43
|
}
|
|
66
44
|
|
|
67
|
-
contents
|
|
45
|
+
contents += source.slice(sourceOffset);
|
|
68
46
|
return {
|
|
69
47
|
contents,
|
|
70
48
|
data: {
|
|
@@ -72,19 +50,3 @@ export const preprocess: GlintExtensionPreprocess<PreprocessData> = (source, pat
|
|
|
72
50
|
},
|
|
73
51
|
};
|
|
74
52
|
};
|
|
75
|
-
|
|
76
|
-
function byteToCharIndex(str: string, byteOffset: number): number {
|
|
77
|
-
const buf = getBuffer(str);
|
|
78
|
-
return buf.subarray(0, byteOffset).toString().length;
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
const BufferMap = new Map();
|
|
82
|
-
|
|
83
|
-
function getBuffer(str: string): Buffer {
|
|
84
|
-
let buf = BufferMap.get(str);
|
|
85
|
-
if (!buf) {
|
|
86
|
-
buf = Buffer.from(str);
|
|
87
|
-
BufferMap.set(str, buf);
|
|
88
|
-
}
|
|
89
|
-
return buf;
|
|
90
|
-
}
|