@atlaspack/transformer-html 2.14.5-canary.20 → 2.14.5-canary.200
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/CHANGELOG.md +207 -0
- package/lib/HTMLTransformer.js +4 -0
- package/lib/dependencies.js +10 -0
- package/lib/inline.js +14 -3
- package/lib/types/HTMLTransformer.d.ts +6 -0
- package/lib/types/dependencies.d.ts +2 -0
- package/lib/types/inline.d.ts +7 -0
- package/package.json +14 -10
- package/src/{HTMLTransformer.js → HTMLTransformer.ts} +9 -7
- package/src/{dependencies.js → dependencies.ts} +26 -15
- package/src/{inline.js → inline.ts} +21 -7
- package/test/{HTMLTransformer.test.js → HTMLTransformer.test.ts} +41 -27
- package/tsconfig.json +4 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,212 @@
|
|
|
1
1
|
# @atlaspack/transformer-html
|
|
2
2
|
|
|
3
|
+
## 2.15.8
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#785](https://github.com/atlassian-labs/atlaspack/pull/785) [`0e7dd5e`](https://github.com/atlassian-labs/atlaspack/commit/0e7dd5ec6fbe05aa9e0bb5775a9d0975f206a922) Thanks [@matt-koko](https://github.com/matt-koko)! - We need to re-publish every package in Atlaspack with the corrected types field.
|
|
8
|
+
|
|
9
|
+
- Updated dependencies [[`0e7dd5e`](https://github.com/atlassian-labs/atlaspack/commit/0e7dd5ec6fbe05aa9e0bb5775a9d0975f206a922), [`686a398`](https://github.com/atlassian-labs/atlaspack/commit/686a398faa1f9e19cbf9274add2c46e246bafba8)]:
|
|
10
|
+
- @atlaspack/diagnostic@2.14.4
|
|
11
|
+
- @atlaspack/feature-flags@2.25.1
|
|
12
|
+
- @atlaspack/plugin@2.14.31
|
|
13
|
+
- @atlaspack/rust@3.8.1
|
|
14
|
+
|
|
15
|
+
## 2.15.7
|
|
16
|
+
|
|
17
|
+
### Patch Changes
|
|
18
|
+
|
|
19
|
+
- Updated dependencies [[`7a52bab`](https://github.com/atlassian-labs/atlaspack/commit/7a52bab6281e8edbfa66af248eb6f872c6b4b7bd), [`eedcbc4`](https://github.com/atlassian-labs/atlaspack/commit/eedcbc408fc1e86a2a8e25f1a41c57146d8529e1), [`5a0363f`](https://github.com/atlassian-labs/atlaspack/commit/5a0363f1086e81068959b87e92064bed5a11a9b4), [`038e87a`](https://github.com/atlassian-labs/atlaspack/commit/038e87a7858d39556d59d3a2d17db534d45f62c6), [`f6532d7`](https://github.com/atlassian-labs/atlaspack/commit/f6532d7a4f7f007bd4e5e36af04dd466f0b9f572), [`0684997`](https://github.com/atlassian-labs/atlaspack/commit/0684997c127a6204af1376b36e556fddd1ba5557), [`602f8ed`](https://github.com/atlassian-labs/atlaspack/commit/602f8ed9d8381301df8b2cc82c1d5cf6f2f94fec)]:
|
|
20
|
+
- @atlaspack/feature-flags@2.25.0
|
|
21
|
+
- @atlaspack/rust@3.8.0
|
|
22
|
+
- @atlaspack/plugin@2.14.30
|
|
23
|
+
|
|
24
|
+
## 2.15.6
|
|
25
|
+
|
|
26
|
+
### Patch Changes
|
|
27
|
+
|
|
28
|
+
- Updated dependencies [[`830261d`](https://github.com/atlassian-labs/atlaspack/commit/830261dcf4a40293090b61cab52fd75d5683c73f), [`53dd47b`](https://github.com/atlassian-labs/atlaspack/commit/53dd47bd6d23cd47f87297347f03a609ab38a03d)]:
|
|
29
|
+
- @atlaspack/feature-flags@2.24.1
|
|
30
|
+
- @atlaspack/rust@3.7.0
|
|
31
|
+
- @atlaspack/plugin@2.14.29
|
|
32
|
+
|
|
33
|
+
## 2.15.5
|
|
34
|
+
|
|
35
|
+
### Patch Changes
|
|
36
|
+
|
|
37
|
+
- Updated dependencies [[`f0349a6`](https://github.com/atlassian-labs/atlaspack/commit/f0349a6b9b04755088f121095ca6301a2ada3767), [`a5081c3`](https://github.com/atlassian-labs/atlaspack/commit/a5081c3f9207d28716ee4edd3841de1830ea4b80), [`f930003`](https://github.com/atlassian-labs/atlaspack/commit/f930003364fdc31e5487520ebe256f1a9389f579), [`f930003`](https://github.com/atlassian-labs/atlaspack/commit/f930003364fdc31e5487520ebe256f1a9389f579), [`8843980`](https://github.com/atlassian-labs/atlaspack/commit/88439807be20025fd3433380204ff1205079729e)]:
|
|
38
|
+
- @atlaspack/feature-flags@2.24.0
|
|
39
|
+
- @atlaspack/plugin@2.14.28
|
|
40
|
+
|
|
41
|
+
## 2.15.4
|
|
42
|
+
|
|
43
|
+
### Patch Changes
|
|
44
|
+
|
|
45
|
+
- [#757](https://github.com/atlassian-labs/atlaspack/pull/757) [`3cfb7cf`](https://github.com/atlassian-labs/atlaspack/commit/3cfb7cfd90b78a5c48ce717e779ff789769825a3) Thanks [@marcins](https://github.com/marcins)! - Clean up the `inlineIsolatedScripts` feature flag
|
|
46
|
+
|
|
47
|
+
- Updated dependencies [[`3cfb7cf`](https://github.com/atlassian-labs/atlaspack/commit/3cfb7cfd90b78a5c48ce717e779ff789769825a3)]:
|
|
48
|
+
- @atlaspack/feature-flags@2.23.2
|
|
49
|
+
- @atlaspack/rust@3.6.2
|
|
50
|
+
- @atlaspack/plugin@2.14.27
|
|
51
|
+
|
|
52
|
+
## 2.15.3
|
|
53
|
+
|
|
54
|
+
### Patch Changes
|
|
55
|
+
|
|
56
|
+
- [#742](https://github.com/atlassian-labs/atlaspack/pull/742) [`ee040bb`](https://github.com/atlassian-labs/atlaspack/commit/ee040bb6428f29b57d892ddd8107e29077d08ffd) Thanks [@yamadapc](https://github.com/yamadapc)! - Internal changes and bug fixes to environmentDeduplication flag
|
|
57
|
+
|
|
58
|
+
- Updated dependencies [[`ee040bb`](https://github.com/atlassian-labs/atlaspack/commit/ee040bb6428f29b57d892ddd8107e29077d08ffd)]:
|
|
59
|
+
- @atlaspack/feature-flags@2.23.1
|
|
60
|
+
- @atlaspack/diagnostic@2.14.3
|
|
61
|
+
- @atlaspack/plugin@2.14.26
|
|
62
|
+
- @atlaspack/rust@3.6.1
|
|
63
|
+
|
|
64
|
+
## 2.15.2
|
|
65
|
+
|
|
66
|
+
### Patch Changes
|
|
67
|
+
|
|
68
|
+
- Updated dependencies [[`f6b3f22`](https://github.com/atlassian-labs/atlaspack/commit/f6b3f2276c7e417580b49c4879563aab51f156b1)]:
|
|
69
|
+
- @atlaspack/feature-flags@2.23.0
|
|
70
|
+
- @atlaspack/plugin@2.14.25
|
|
71
|
+
|
|
72
|
+
## 2.15.1
|
|
73
|
+
|
|
74
|
+
### Patch Changes
|
|
75
|
+
|
|
76
|
+
- Updated dependencies [[`ad26146`](https://github.com/atlassian-labs/atlaspack/commit/ad26146f13b4c1cc65d4a0f9c67060b90ef14ff3), [`f1b48e7`](https://github.com/atlassian-labs/atlaspack/commit/f1b48e7a04e005cef0f36a3e692087a9ecdb6f7a), [`7f5841c`](https://github.com/atlassian-labs/atlaspack/commit/7f5841c39df049f9546cccbeea2a7337e0337b45), [`73dd7ba`](https://github.com/atlassian-labs/atlaspack/commit/73dd7baab69456ef2f6e4a0cc7dbb04f407eb148)]:
|
|
77
|
+
- @atlaspack/rust@3.6.0
|
|
78
|
+
- @atlaspack/feature-flags@2.22.0
|
|
79
|
+
- @atlaspack/plugin@2.14.24
|
|
80
|
+
|
|
81
|
+
## 2.15.0
|
|
82
|
+
|
|
83
|
+
### Minor Changes
|
|
84
|
+
|
|
85
|
+
- [#731](https://github.com/atlassian-labs/atlaspack/pull/731) [`23d561e`](https://github.com/atlassian-labs/atlaspack/commit/23d561e51e68b0c38fd1ff4e4fb173e5e7b01cf2) Thanks [@marcins](https://github.com/marcins)! - Implement "inline isolated" scripts
|
|
86
|
+
|
|
87
|
+
### Patch Changes
|
|
88
|
+
|
|
89
|
+
- Updated dependencies [[`23d561e`](https://github.com/atlassian-labs/atlaspack/commit/23d561e51e68b0c38fd1ff4e4fb173e5e7b01cf2)]:
|
|
90
|
+
- @atlaspack/feature-flags@2.21.0
|
|
91
|
+
- @atlaspack/rust@3.5.0
|
|
92
|
+
- @atlaspack/plugin@2.14.23
|
|
93
|
+
|
|
94
|
+
## 2.14.22
|
|
95
|
+
|
|
96
|
+
### Patch Changes
|
|
97
|
+
|
|
98
|
+
- [#720](https://github.com/atlassian-labs/atlaspack/pull/720) [`d2fd849`](https://github.com/atlassian-labs/atlaspack/commit/d2fd849770fe6305e9c694bd97b1bd905abd9d94) Thanks [@alshdavid](https://github.com/alshdavid)! - Migrate to TypeScript
|
|
99
|
+
|
|
100
|
+
- Updated dependencies [[`d2fd849`](https://github.com/atlassian-labs/atlaspack/commit/d2fd849770fe6305e9c694bd97b1bd905abd9d94)]:
|
|
101
|
+
- @atlaspack/diagnostic@2.14.2
|
|
102
|
+
- @atlaspack/plugin@2.14.22
|
|
103
|
+
- @atlaspack/rust@3.4.2
|
|
104
|
+
|
|
105
|
+
## 2.14.21
|
|
106
|
+
|
|
107
|
+
### Patch Changes
|
|
108
|
+
|
|
109
|
+
- Updated dependencies []:
|
|
110
|
+
- @atlaspack/plugin@2.14.21
|
|
111
|
+
|
|
112
|
+
## 2.14.20
|
|
113
|
+
|
|
114
|
+
### Patch Changes
|
|
115
|
+
|
|
116
|
+
- [#702](https://github.com/atlassian-labs/atlaspack/pull/702) [`daaa768`](https://github.com/atlassian-labs/atlaspack/commit/daaa7688786772d7e3713b71c5bba6b89ec704aa) Thanks [@alshdavid](https://github.com/alshdavid)! - Fixes to Flow types
|
|
117
|
+
|
|
118
|
+
- Updated dependencies [[`daaa768`](https://github.com/atlassian-labs/atlaspack/commit/daaa7688786772d7e3713b71c5bba6b89ec704aa)]:
|
|
119
|
+
- @atlaspack/plugin@2.14.20
|
|
120
|
+
|
|
121
|
+
## 2.14.19
|
|
122
|
+
|
|
123
|
+
### Patch Changes
|
|
124
|
+
|
|
125
|
+
- Updated dependencies []:
|
|
126
|
+
- @atlaspack/plugin@2.14.19
|
|
127
|
+
|
|
128
|
+
## 2.14.18
|
|
129
|
+
|
|
130
|
+
### Patch Changes
|
|
131
|
+
|
|
132
|
+
- Updated dependencies [[`becf977`](https://github.com/atlassian-labs/atlaspack/commit/becf977f625d5ee46dae3d4c679f173bf5f40cc0), [`f0f7c71`](https://github.com/atlassian-labs/atlaspack/commit/f0f7c7168a1d3d18c6f30d2daed611275692b7c5)]:
|
|
133
|
+
- @atlaspack/rust@3.4.1
|
|
134
|
+
- @atlaspack/plugin@2.14.18
|
|
135
|
+
|
|
136
|
+
## 2.14.17
|
|
137
|
+
|
|
138
|
+
### Patch Changes
|
|
139
|
+
|
|
140
|
+
- Updated dependencies [[`c75bf55`](https://github.com/atlassian-labs/atlaspack/commit/c75bf553fff4decc285b5fd499a275853b18f8f2)]:
|
|
141
|
+
- @atlaspack/rust@3.4.0
|
|
142
|
+
- @atlaspack/plugin@2.14.17
|
|
143
|
+
|
|
144
|
+
## 2.14.16
|
|
145
|
+
|
|
146
|
+
### Patch Changes
|
|
147
|
+
|
|
148
|
+
- Updated dependencies []:
|
|
149
|
+
- @atlaspack/plugin@2.14.16
|
|
150
|
+
|
|
151
|
+
## 2.14.15
|
|
152
|
+
|
|
153
|
+
### Patch Changes
|
|
154
|
+
|
|
155
|
+
- Updated dependencies []:
|
|
156
|
+
- @atlaspack/plugin@2.14.15
|
|
157
|
+
|
|
158
|
+
## 2.14.14
|
|
159
|
+
|
|
160
|
+
### Patch Changes
|
|
161
|
+
|
|
162
|
+
- Updated dependencies []:
|
|
163
|
+
- @atlaspack/plugin@2.14.14
|
|
164
|
+
|
|
165
|
+
## 2.14.13
|
|
166
|
+
|
|
167
|
+
### Patch Changes
|
|
168
|
+
|
|
169
|
+
- Updated dependencies []:
|
|
170
|
+
- @atlaspack/plugin@2.14.13
|
|
171
|
+
|
|
172
|
+
## 2.14.12
|
|
173
|
+
|
|
174
|
+
### Patch Changes
|
|
175
|
+
|
|
176
|
+
- Updated dependencies []:
|
|
177
|
+
- @atlaspack/plugin@2.14.12
|
|
178
|
+
|
|
179
|
+
## 2.14.11
|
|
180
|
+
|
|
181
|
+
### Patch Changes
|
|
182
|
+
|
|
183
|
+
- Updated dependencies []:
|
|
184
|
+
- @atlaspack/plugin@2.14.11
|
|
185
|
+
|
|
186
|
+
## 2.14.10
|
|
187
|
+
|
|
188
|
+
### Patch Changes
|
|
189
|
+
|
|
190
|
+
- Updated dependencies [[`35fdd4b`](https://github.com/atlassian-labs/atlaspack/commit/35fdd4b52da0af20f74667f7b8adfb2f90279b7c), [`6dd4ccb`](https://github.com/atlassian-labs/atlaspack/commit/6dd4ccb753541de32322d881f973d571dd57e4ca)]:
|
|
191
|
+
- @atlaspack/rust@3.3.5
|
|
192
|
+
- @atlaspack/plugin@2.14.10
|
|
193
|
+
|
|
194
|
+
## 2.14.9
|
|
195
|
+
|
|
196
|
+
### Patch Changes
|
|
197
|
+
|
|
198
|
+
- Updated dependencies [[`124b7ff`](https://github.com/atlassian-labs/atlaspack/commit/124b7fff44f71aac9fbad289a9a9509b3dfc9aaa), [`e052521`](https://github.com/atlassian-labs/atlaspack/commit/e0525210850ed1606146eb86991049cf567c5dec), [`15c6d70`](https://github.com/atlassian-labs/atlaspack/commit/15c6d7000bd89da876bc590aa75b17a619a41896), [`e4d966c`](https://github.com/atlassian-labs/atlaspack/commit/e4d966c3c9c4292c5013372ae65b10d19d4bacc6), [`42a775d`](https://github.com/atlassian-labs/atlaspack/commit/42a775de8eec638ad188f3271964170d8c04d84b), [`29c2f10`](https://github.com/atlassian-labs/atlaspack/commit/29c2f106de9679adfb5afa04e1910471dc65a427), [`1ef91fc`](https://github.com/atlassian-labs/atlaspack/commit/1ef91fcc863fdd2831511937083dbbc1263b3d9d)]:
|
|
199
|
+
- @atlaspack/rust@3.3.4
|
|
200
|
+
- @atlaspack/plugin@2.14.9
|
|
201
|
+
|
|
202
|
+
## 2.14.8
|
|
203
|
+
|
|
204
|
+
### Patch Changes
|
|
205
|
+
|
|
206
|
+
- Updated dependencies [[`1ab0a27`](https://github.com/atlassian-labs/atlaspack/commit/1ab0a275aeca40350415e2b03e7440d1dddc6228), [`b8a4ae8`](https://github.com/atlassian-labs/atlaspack/commit/b8a4ae8f83dc0a83d8b145c5f729936ce52080a3)]:
|
|
207
|
+
- @atlaspack/rust@3.3.3
|
|
208
|
+
- @atlaspack/plugin@2.14.8
|
|
209
|
+
|
|
3
210
|
## 2.14.7
|
|
4
211
|
|
|
5
212
|
### Patch Changes
|
package/lib/HTMLTransformer.js
CHANGED
|
@@ -58,6 +58,8 @@ function _diagnostic() {
|
|
|
58
58
|
return data;
|
|
59
59
|
}
|
|
60
60
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
61
|
+
// @ts-expect-error TS2305
|
|
62
|
+
|
|
61
63
|
function parseHTML(code, xmlMode) {
|
|
62
64
|
return {
|
|
63
65
|
type: 'posthtml',
|
|
@@ -156,6 +158,7 @@ const transformerOpts = exports.transformerOpts = {
|
|
|
156
158
|
}) {
|
|
157
159
|
return {
|
|
158
160
|
content: (0, _posthtmlRender().render)(ast.program, {
|
|
161
|
+
// @ts-expect-error TS2322
|
|
159
162
|
closingSingleTag: asset.type === 'xhtml' ? 'slash' : undefined
|
|
160
163
|
})
|
|
161
164
|
};
|
|
@@ -165,6 +168,7 @@ var _default = exports.default = new (_plugin().Transformer)(transformerOpts);
|
|
|
165
168
|
function findFirstMatch(ast, expressions) {
|
|
166
169
|
let found;
|
|
167
170
|
for (const expression of expressions) {
|
|
171
|
+
// @ts-expect-error TS2339
|
|
168
172
|
(0, _posthtml().default)().match.call(ast.program, expression, node => {
|
|
169
173
|
found = node;
|
|
170
174
|
return node;
|
package/lib/dependencies.js
CHANGED
|
@@ -19,6 +19,8 @@ function _srcset() {
|
|
|
19
19
|
return data;
|
|
20
20
|
}
|
|
21
21
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
22
|
+
// @ts-expect-error TS2724
|
|
23
|
+
|
|
22
24
|
// A list of all attributes that may produce a dependency
|
|
23
25
|
// Based on https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes
|
|
24
26
|
const ATTRS = {
|
|
@@ -89,6 +91,7 @@ function collectDependencies(asset, ast) {
|
|
|
89
91
|
let hasModuleScripts = false;
|
|
90
92
|
let seen = new Set();
|
|
91
93
|
let errors = [];
|
|
94
|
+
// @ts-expect-error TS2339
|
|
92
95
|
(0, _posthtml().default)().walk.call(ast.program, node => {
|
|
93
96
|
let {
|
|
94
97
|
tag,
|
|
@@ -100,6 +103,7 @@ function collectDependencies(asset, ast) {
|
|
|
100
103
|
seen.add(node);
|
|
101
104
|
if (tag === 'meta') {
|
|
102
105
|
const isMetaDependency = Object.keys(attrs).some(attr => {
|
|
106
|
+
// @ts-expect-error TS7053
|
|
103
107
|
let values = META[attr];
|
|
104
108
|
return values && values.includes(attrs[attr]) && attrs.content !== '' && !(attrs.name === 'msapplication-config' && attrs.content === 'none');
|
|
105
109
|
});
|
|
@@ -169,6 +173,7 @@ function collectDependencies(asset, ast) {
|
|
|
169
173
|
priority: 'parallel',
|
|
170
174
|
bundleBehavior: sourceType === 'script' || attrs.async != null ? 'isolated' : undefined,
|
|
171
175
|
env: {
|
|
176
|
+
// @ts-expect-error TS2322
|
|
172
177
|
sourceType,
|
|
173
178
|
outputFormat: 'global',
|
|
174
179
|
loc
|
|
@@ -185,7 +190,9 @@ function collectDependencies(asset, ast) {
|
|
|
185
190
|
// because nomodule scripts won't run when modules are supported.
|
|
186
191
|
bundleBehavior: sourceType === 'script' || attrs.async != null ? 'isolated' : undefined,
|
|
187
192
|
env: {
|
|
193
|
+
// @ts-expect-error TS2322
|
|
188
194
|
sourceType,
|
|
195
|
+
// @ts-expect-error TS2322
|
|
189
196
|
outputFormat,
|
|
190
197
|
loc
|
|
191
198
|
}
|
|
@@ -204,6 +211,8 @@ function collectDependencies(asset, ast) {
|
|
|
204
211
|
if (attrs[attr][0] === '#') {
|
|
205
212
|
continue;
|
|
206
213
|
}
|
|
214
|
+
|
|
215
|
+
// @ts-expect-error TS7053
|
|
207
216
|
let elements = ATTRS[attr];
|
|
208
217
|
if (elements && elements.includes(node.tag)) {
|
|
209
218
|
// Check for empty string
|
|
@@ -215,6 +224,7 @@ function collectDependencies(asset, ast) {
|
|
|
215
224
|
});
|
|
216
225
|
}
|
|
217
226
|
let depHandler = getAttrDepHandler(attr);
|
|
227
|
+
// @ts-expect-error TS7053
|
|
218
228
|
let depOptionsHandler = OPTIONS[node.tag];
|
|
219
229
|
let depOptions = typeof depOptionsHandler === 'function' ? depOptionsHandler(attrs, asset.env) : depOptionsHandler && depOptionsHandler[attr];
|
|
220
230
|
attrs[attr] = depHandler(asset, attrs[attr], depOptions);
|
package/lib/inline.js
CHANGED
|
@@ -19,6 +19,8 @@ function _posthtml() {
|
|
|
19
19
|
return data;
|
|
20
20
|
}
|
|
21
21
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
22
|
+
// @ts-expect-error TS2724
|
|
23
|
+
|
|
22
24
|
const SCRIPT_TYPES = {
|
|
23
25
|
'application/javascript': 'js',
|
|
24
26
|
'text/javascript': 'js',
|
|
@@ -34,6 +36,7 @@ function extractInlineAssets(asset, ast) {
|
|
|
34
36
|
// Extract inline <script> and <style> tags for processing.
|
|
35
37
|
let parts = [];
|
|
36
38
|
let hasModuleScripts = false;
|
|
39
|
+
// @ts-expect-error TS2339
|
|
37
40
|
(0, _posthtml().default)().walk.call(program, node => {
|
|
38
41
|
let parcelKey = (0, _rust().hashString)(`${asset.id}:${key++}`);
|
|
39
42
|
if (node.tag === 'script' || node.tag === 'style') {
|
|
@@ -49,10 +52,14 @@ function extractInlineAssets(asset, ast) {
|
|
|
49
52
|
}
|
|
50
53
|
} else if (node.attrs && node.attrs.type != null) {
|
|
51
54
|
// Skip JSON
|
|
55
|
+
// @ts-expect-error TS7053
|
|
52
56
|
if (SCRIPT_TYPES[node.attrs.type] === false) {
|
|
53
57
|
return node;
|
|
54
58
|
}
|
|
59
|
+
|
|
60
|
+
// @ts-expect-error TS7053
|
|
55
61
|
if (SCRIPT_TYPES[node.attrs.type]) {
|
|
62
|
+
// @ts-expect-error TS7053
|
|
56
63
|
type = SCRIPT_TYPES[node.attrs.type];
|
|
57
64
|
} else {
|
|
58
65
|
type = node.attrs.type.split('/')[1];
|
|
@@ -106,6 +113,11 @@ function extractInlineAssets(asset, ast) {
|
|
|
106
113
|
if ((_node$attrs = node.attrs) !== null && _node$attrs !== void 0 && _node$attrs.type && node.tag === 'style') {
|
|
107
114
|
delete node.attrs.type;
|
|
108
115
|
}
|
|
116
|
+
let bundleBehavior = 'inline';
|
|
117
|
+
if (typeof node.attrs['data-atlaspack-isolated'] !== 'undefined') {
|
|
118
|
+
bundleBehavior = 'inlineIsolated';
|
|
119
|
+
delete node.attrs['data-atlaspack-isolated'];
|
|
120
|
+
}
|
|
109
121
|
|
|
110
122
|
// insert parcelId to allow us to retrieve node during packaging
|
|
111
123
|
node.attrs['data-parcel-key'] = parcelKey;
|
|
@@ -119,11 +131,11 @@ function extractInlineAssets(asset, ast) {
|
|
|
119
131
|
type,
|
|
120
132
|
content: value,
|
|
121
133
|
uniqueKey: parcelKey,
|
|
122
|
-
bundleBehavior
|
|
134
|
+
bundleBehavior,
|
|
135
|
+
// @ts-expect-error TS2322
|
|
123
136
|
env,
|
|
124
137
|
meta: {
|
|
125
138
|
type: 'tag',
|
|
126
|
-
// $FlowFixMe
|
|
127
139
|
node,
|
|
128
140
|
startLine: (_node$location = node.location) === null || _node$location === void 0 ? void 0 : _node$location.start.line
|
|
129
141
|
}
|
|
@@ -151,7 +163,6 @@ function extractInlineAssets(asset, ast) {
|
|
|
151
163
|
bundleBehavior: 'inline',
|
|
152
164
|
meta: {
|
|
153
165
|
type: 'attr',
|
|
154
|
-
// $FlowFixMe
|
|
155
166
|
node
|
|
156
167
|
}
|
|
157
168
|
});
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { Transformer } from '@atlaspack/plugin';
|
|
2
|
+
import type { AST, Transformer as TransformerOpts } from '@atlaspack/types';
|
|
3
|
+
export declare function parseHTML(code: string, xmlMode: boolean): AST;
|
|
4
|
+
export declare const transformerOpts: TransformerOpts<undefined>;
|
|
5
|
+
declare const _default: Transformer<undefined>;
|
|
6
|
+
export default _default;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { AST, MutableAsset, TransformerResult } from '@atlaspack/types';
|
|
2
|
+
interface ExtractInlineAssetsResult {
|
|
3
|
+
hasModuleScripts: boolean;
|
|
4
|
+
assets: Array<TransformerResult>;
|
|
5
|
+
}
|
|
6
|
+
export default function extractInlineAssets(asset: MutableAsset, ast: AST): ExtractInlineAssetsResult;
|
|
7
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,26 +1,30 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaspack/transformer-html",
|
|
3
|
-
"version": "2.14.5-canary.
|
|
3
|
+
"version": "2.14.5-canary.200+10ee3fa5b",
|
|
4
4
|
"license": "(MIT OR Apache-2.0)",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
7
7
|
},
|
|
8
8
|
"scripts": {
|
|
9
|
-
"test": "mocha"
|
|
9
|
+
"test": "mocha",
|
|
10
|
+
"check-ts": "tsc --emitDeclarationOnly --rootDir src",
|
|
11
|
+
"build:lib": "gulp build --gulpfile ../../../gulpfile.js --cwd ."
|
|
10
12
|
},
|
|
11
13
|
"repository": {
|
|
12
14
|
"type": "git",
|
|
13
15
|
"url": "https://github.com/atlassian-labs/atlaspack.git"
|
|
14
16
|
},
|
|
15
|
-
"main": "lib/HTMLTransformer.js",
|
|
16
|
-
"source": "src/HTMLTransformer.
|
|
17
|
+
"main": "./lib/HTMLTransformer.js",
|
|
18
|
+
"source": "./src/HTMLTransformer.ts",
|
|
19
|
+
"types": "./lib/types/HTMLTransformer.d.ts",
|
|
17
20
|
"engines": {
|
|
18
21
|
"node": ">= 16.0.0"
|
|
19
22
|
},
|
|
20
23
|
"dependencies": {
|
|
21
|
-
"@atlaspack/diagnostic": "2.14.1-canary.
|
|
22
|
-
"@atlaspack/
|
|
23
|
-
"@atlaspack/
|
|
24
|
+
"@atlaspack/diagnostic": "2.14.1-canary.268+10ee3fa5b",
|
|
25
|
+
"@atlaspack/feature-flags": "2.14.1-canary.268+10ee3fa5b",
|
|
26
|
+
"@atlaspack/plugin": "2.14.5-canary.200+10ee3fa5b",
|
|
27
|
+
"@atlaspack/rust": "3.2.1-canary.200+10ee3fa5b",
|
|
24
28
|
"nullthrows": "^1.1.1",
|
|
25
29
|
"posthtml": "^0.16.5",
|
|
26
30
|
"posthtml-parser": "^0.10.1",
|
|
@@ -29,8 +33,8 @@
|
|
|
29
33
|
"srcset": "4"
|
|
30
34
|
},
|
|
31
35
|
"devDependencies": {
|
|
32
|
-
"@atlaspack/core": "2.16.2-canary.
|
|
36
|
+
"@atlaspack/core": "2.16.2-canary.200+10ee3fa5b"
|
|
33
37
|
},
|
|
34
38
|
"type": "commonjs",
|
|
35
|
-
"gitHead": "
|
|
36
|
-
}
|
|
39
|
+
"gitHead": "10ee3fa5b75a92acde8973673d9b3c5b6f3958e5"
|
|
40
|
+
}
|
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
// @flow
|
|
2
|
-
|
|
3
1
|
import {Transformer} from '@atlaspack/plugin';
|
|
4
2
|
import type {AST, Transformer as TransformerOpts} from '@atlaspack/types';
|
|
5
3
|
import {parser as parse} from 'posthtml-parser';
|
|
6
4
|
import nullthrows from 'nullthrows';
|
|
5
|
+
// @ts-expect-error TS2305
|
|
7
6
|
import type {PostHTMLExpression, PostHTMLNode} from 'posthtml';
|
|
8
7
|
import PostHTML from 'posthtml';
|
|
9
8
|
import {render} from 'posthtml-render';
|
|
@@ -25,7 +24,7 @@ export function parseHTML(code: string, xmlMode: boolean): AST {
|
|
|
25
24
|
};
|
|
26
25
|
}
|
|
27
26
|
|
|
28
|
-
export const transformerOpts: TransformerOpts<
|
|
27
|
+
export const transformerOpts: TransformerOpts<undefined> = {
|
|
29
28
|
canReuseAST({ast}) {
|
|
30
29
|
return ast.type === 'posthtml' && semver.satisfies(ast.version, '^0.4.0');
|
|
31
30
|
},
|
|
@@ -46,7 +45,7 @@ export const transformerOpts: TransformerOpts<void> = {
|
|
|
46
45
|
let hasModuleScripts;
|
|
47
46
|
try {
|
|
48
47
|
hasModuleScripts = collectDependencies(asset, ast);
|
|
49
|
-
} catch (errors) {
|
|
48
|
+
} catch (errors: any) {
|
|
50
49
|
if (Array.isArray(errors)) {
|
|
51
50
|
throw new ThrowableDiagnostic({
|
|
52
51
|
diagnostic: errors.map((error) => ({
|
|
@@ -81,7 +80,7 @@ export const transformerOpts: TransformerOpts<void> = {
|
|
|
81
80
|
}),
|
|
82
81
|
},
|
|
83
82
|
content: [],
|
|
84
|
-
};
|
|
83
|
+
} as const;
|
|
85
84
|
|
|
86
85
|
const found = findFirstMatch(ast, [{tag: 'body'}, {tag: 'html'}]);
|
|
87
86
|
|
|
@@ -108,20 +107,23 @@ export const transformerOpts: TransformerOpts<void> = {
|
|
|
108
107
|
generate({ast, asset}) {
|
|
109
108
|
return {
|
|
110
109
|
content: render(ast.program, {
|
|
110
|
+
// @ts-expect-error TS2322
|
|
111
111
|
closingSingleTag: asset.type === 'xhtml' ? 'slash' : undefined,
|
|
112
112
|
}),
|
|
113
113
|
};
|
|
114
114
|
},
|
|
115
115
|
};
|
|
116
|
-
|
|
116
|
+
|
|
117
|
+
export default new Transformer(transformerOpts) as Transformer<undefined>;
|
|
117
118
|
|
|
118
119
|
function findFirstMatch(
|
|
119
120
|
ast: AST,
|
|
120
121
|
expressions: PostHTMLExpression[],
|
|
121
|
-
):
|
|
122
|
+
): PostHTMLNode | null | undefined {
|
|
122
123
|
let found;
|
|
123
124
|
|
|
124
125
|
for (const expression of expressions) {
|
|
126
|
+
// @ts-expect-error TS2339
|
|
125
127
|
PostHTML().match.call(ast.program, expression, (node) => {
|
|
126
128
|
found = node;
|
|
127
129
|
return node;
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
// @flow
|
|
2
|
-
|
|
3
1
|
import type {AST, MutableAsset, FilePath} from '@atlaspack/types';
|
|
2
|
+
// @ts-expect-error TS2724
|
|
4
3
|
import type {PostHTMLNode} from 'posthtml';
|
|
5
4
|
import PostHTML from 'posthtml';
|
|
6
5
|
import {parse, stringify} from 'srcset';
|
|
@@ -26,7 +25,7 @@ const ATTRS = {
|
|
|
26
25
|
'xlink:href': ['use', 'image', 'script'],
|
|
27
26
|
content: ['meta'],
|
|
28
27
|
data: ['object'],
|
|
29
|
-
};
|
|
28
|
+
} as const;
|
|
30
29
|
|
|
31
30
|
// A list of metadata that should produce a dependency
|
|
32
31
|
// Based on:
|
|
@@ -63,7 +62,7 @@ const META = {
|
|
|
63
62
|
'contentUrl',
|
|
64
63
|
'downloadUrl',
|
|
65
64
|
],
|
|
66
|
-
};
|
|
65
|
+
} as const;
|
|
67
66
|
|
|
68
67
|
const FEED_TYPES = new Set(['application/rss+xml', 'application/atom+xml']);
|
|
69
68
|
|
|
@@ -75,7 +74,7 @@ const OPTIONS = {
|
|
|
75
74
|
iframe: {
|
|
76
75
|
src: {needsStableName: true},
|
|
77
76
|
},
|
|
78
|
-
link(attrs) {
|
|
77
|
+
link(attrs: any) {
|
|
79
78
|
if (attrs.rel === 'stylesheet') {
|
|
80
79
|
return {
|
|
81
80
|
// Keep in the same bundle group as the HTML.
|
|
@@ -83,9 +82,13 @@ const OPTIONS = {
|
|
|
83
82
|
};
|
|
84
83
|
}
|
|
85
84
|
},
|
|
86
|
-
};
|
|
85
|
+
} as const;
|
|
87
86
|
|
|
88
|
-
function collectSrcSetDependencies(
|
|
87
|
+
function collectSrcSetDependencies(
|
|
88
|
+
asset: MutableAsset,
|
|
89
|
+
srcset: string,
|
|
90
|
+
opts: any,
|
|
91
|
+
) {
|
|
89
92
|
let parsed = parse(srcset).map(({url, ...v}) => ({
|
|
90
93
|
url: asset.addURLDependency(url, opts),
|
|
91
94
|
...v,
|
|
@@ -93,12 +96,13 @@ function collectSrcSetDependencies(asset, srcset, opts) {
|
|
|
93
96
|
return stringify(parsed);
|
|
94
97
|
}
|
|
95
98
|
|
|
96
|
-
function getAttrDepHandler(attr) {
|
|
99
|
+
function getAttrDepHandler(attr: string) {
|
|
97
100
|
if (attr === 'srcset' || attr === 'imagesrcset') {
|
|
98
101
|
return collectSrcSetDependencies;
|
|
99
102
|
}
|
|
100
103
|
|
|
101
|
-
return (asset, src, opts) =>
|
|
104
|
+
return (asset: MutableAsset, src: string, opts: any) =>
|
|
105
|
+
asset.addURLDependency(src, opts);
|
|
102
106
|
}
|
|
103
107
|
|
|
104
108
|
export default function collectDependencies(
|
|
@@ -108,11 +112,12 @@ export default function collectDependencies(
|
|
|
108
112
|
let isDirty = false;
|
|
109
113
|
let hasModuleScripts = false;
|
|
110
114
|
let seen = new Set();
|
|
111
|
-
let errors: Array<{
|
|
112
|
-
message: string
|
|
113
|
-
filePath: FilePath
|
|
114
|
-
loc: PostHTMLNode['location']
|
|
115
|
-
|
|
115
|
+
let errors: Array<{
|
|
116
|
+
message: string;
|
|
117
|
+
filePath: FilePath;
|
|
118
|
+
loc: PostHTMLNode['location'];
|
|
119
|
+
}> = [];
|
|
120
|
+
// @ts-expect-error TS2339
|
|
116
121
|
PostHTML().walk.call(ast.program, (node) => {
|
|
117
122
|
let {tag, attrs} = node;
|
|
118
123
|
if (!attrs || seen.has(node)) {
|
|
@@ -123,6 +128,7 @@ export default function collectDependencies(
|
|
|
123
128
|
|
|
124
129
|
if (tag === 'meta') {
|
|
125
130
|
const isMetaDependency = Object.keys(attrs).some((attr) => {
|
|
131
|
+
// @ts-expect-error TS7053
|
|
126
132
|
let values = META[attr];
|
|
127
133
|
return (
|
|
128
134
|
values &&
|
|
@@ -197,7 +203,7 @@ export default function collectDependencies(
|
|
|
197
203
|
|
|
198
204
|
// If this is a <script type="module">, and not all of the browser targets support ESM natively,
|
|
199
205
|
// add a copy of the script tag with a nomodule attribute.
|
|
200
|
-
let copy:
|
|
206
|
+
let copy: PostHTMLNode | null | undefined;
|
|
201
207
|
if (
|
|
202
208
|
outputFormat === 'esmodule' &&
|
|
203
209
|
!asset.env.supports('esmodules', true)
|
|
@@ -215,6 +221,7 @@ export default function collectDependencies(
|
|
|
215
221
|
? 'isolated'
|
|
216
222
|
: undefined,
|
|
217
223
|
env: {
|
|
224
|
+
// @ts-expect-error TS2322
|
|
218
225
|
sourceType,
|
|
219
226
|
outputFormat: 'global',
|
|
220
227
|
loc,
|
|
@@ -236,7 +243,9 @@ export default function collectDependencies(
|
|
|
236
243
|
? 'isolated'
|
|
237
244
|
: undefined,
|
|
238
245
|
env: {
|
|
246
|
+
// @ts-expect-error TS2322
|
|
239
247
|
sourceType,
|
|
248
|
+
// @ts-expect-error TS2322
|
|
240
249
|
outputFormat,
|
|
241
250
|
loc,
|
|
242
251
|
},
|
|
@@ -258,6 +267,7 @@ export default function collectDependencies(
|
|
|
258
267
|
continue;
|
|
259
268
|
}
|
|
260
269
|
|
|
270
|
+
// @ts-expect-error TS7053
|
|
261
271
|
let elements = ATTRS[attr];
|
|
262
272
|
if (elements && elements.includes(node.tag)) {
|
|
263
273
|
// Check for empty string
|
|
@@ -270,6 +280,7 @@ export default function collectDependencies(
|
|
|
270
280
|
}
|
|
271
281
|
|
|
272
282
|
let depHandler = getAttrDepHandler(attr);
|
|
283
|
+
// @ts-expect-error TS7053
|
|
273
284
|
let depOptionsHandler = OPTIONS[node.tag];
|
|
274
285
|
let depOptions =
|
|
275
286
|
typeof depOptionsHandler === 'function'
|
|
@@ -1,10 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import type {
|
|
2
|
+
AST,
|
|
3
|
+
BundleBehavior,
|
|
4
|
+
MutableAsset,
|
|
5
|
+
TransformerResult,
|
|
6
|
+
} from '@atlaspack/types';
|
|
4
7
|
import {hashString} from '@atlaspack/rust';
|
|
8
|
+
// @ts-expect-error TS2724
|
|
5
9
|
import type {PostHTMLNode} from 'posthtml';
|
|
6
10
|
|
|
7
11
|
import PostHTML from 'posthtml';
|
|
12
|
+
import {getFeatureFlag} from '@atlaspack/feature-flags';
|
|
8
13
|
|
|
9
14
|
const SCRIPT_TYPES = {
|
|
10
15
|
'application/javascript': 'js',
|
|
@@ -13,7 +18,7 @@ const SCRIPT_TYPES = {
|
|
|
13
18
|
'application/ld+json': 'jsonld',
|
|
14
19
|
'text/html': false,
|
|
15
20
|
module: 'js',
|
|
16
|
-
};
|
|
21
|
+
} as const;
|
|
17
22
|
|
|
18
23
|
interface ExtractInlineAssetsResult {
|
|
19
24
|
hasModuleScripts: boolean;
|
|
@@ -30,6 +35,7 @@ export default function extractInlineAssets(
|
|
|
30
35
|
// Extract inline <script> and <style> tags for processing.
|
|
31
36
|
let parts: Array<TransformerResult> = [];
|
|
32
37
|
let hasModuleScripts = false;
|
|
38
|
+
// @ts-expect-error TS2339
|
|
33
39
|
PostHTML().walk.call(program, (node: PostHTMLNode) => {
|
|
34
40
|
let parcelKey = hashString(`${asset.id}:${key++}`);
|
|
35
41
|
if (node.tag === 'script' || node.tag === 'style') {
|
|
@@ -45,11 +51,14 @@ export default function extractInlineAssets(
|
|
|
45
51
|
}
|
|
46
52
|
} else if (node.attrs && node.attrs.type != null) {
|
|
47
53
|
// Skip JSON
|
|
54
|
+
// @ts-expect-error TS7053
|
|
48
55
|
if (SCRIPT_TYPES[node.attrs.type] === false) {
|
|
49
56
|
return node;
|
|
50
57
|
}
|
|
51
58
|
|
|
59
|
+
// @ts-expect-error TS7053
|
|
52
60
|
if (SCRIPT_TYPES[node.attrs.type]) {
|
|
61
|
+
// @ts-expect-error TS7053
|
|
53
62
|
type = SCRIPT_TYPES[node.attrs.type];
|
|
54
63
|
} else {
|
|
55
64
|
type = node.attrs.type.split('/')[1];
|
|
@@ -117,6 +126,12 @@ export default function extractInlineAssets(
|
|
|
117
126
|
delete node.attrs.type;
|
|
118
127
|
}
|
|
119
128
|
|
|
129
|
+
let bundleBehavior: BundleBehavior = 'inline';
|
|
130
|
+
if (typeof node.attrs['data-atlaspack-isolated'] !== 'undefined') {
|
|
131
|
+
bundleBehavior = 'inlineIsolated';
|
|
132
|
+
delete node.attrs['data-atlaspack-isolated'];
|
|
133
|
+
}
|
|
134
|
+
|
|
120
135
|
// insert parcelId to allow us to retrieve node during packaging
|
|
121
136
|
node.attrs['data-parcel-key'] = parcelKey;
|
|
122
137
|
asset.setAST(ast); // mark dirty
|
|
@@ -130,11 +145,11 @@ export default function extractInlineAssets(
|
|
|
130
145
|
type,
|
|
131
146
|
content: value,
|
|
132
147
|
uniqueKey: parcelKey,
|
|
133
|
-
bundleBehavior
|
|
148
|
+
bundleBehavior,
|
|
149
|
+
// @ts-expect-error TS2322
|
|
134
150
|
env,
|
|
135
151
|
meta: {
|
|
136
152
|
type: 'tag',
|
|
137
|
-
// $FlowFixMe
|
|
138
153
|
node,
|
|
139
154
|
startLine: node.location?.start.line,
|
|
140
155
|
},
|
|
@@ -163,7 +178,6 @@ export default function extractInlineAssets(
|
|
|
163
178
|
bundleBehavior: 'inline',
|
|
164
179
|
meta: {
|
|
165
180
|
type: 'attr',
|
|
166
|
-
// $FlowFixMe
|
|
167
181
|
node,
|
|
168
182
|
},
|
|
169
183
|
});
|
|
@@ -1,22 +1,19 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
import {type PostHTMLNode, render} from 'posthtml-render';
|
|
1
|
+
import {PostHTMLNode, render} from 'posthtml-render';
|
|
4
2
|
import {parseHTML, transformerOpts} from '../src/HTMLTransformer';
|
|
5
3
|
import assert from 'assert';
|
|
6
4
|
import type {PluginOptions} from '../../../core/types-internal/src';
|
|
7
5
|
|
|
8
6
|
function normalizeHTML(code: string): string {
|
|
9
7
|
const ast = parseHTML(code, true);
|
|
10
|
-
// $FlowFixMe
|
|
11
8
|
const result = renderHTML(ast);
|
|
12
9
|
const lines = result
|
|
13
10
|
.split('\n')
|
|
14
|
-
.map((line) => line.trim())
|
|
15
|
-
.filter((line) => line);
|
|
11
|
+
.map((line: any) => line.trim())
|
|
12
|
+
.filter((line: any) => line);
|
|
16
13
|
return lines.join('');
|
|
17
14
|
}
|
|
18
15
|
|
|
19
|
-
function renderHTML(newAST: {
|
|
16
|
+
function renderHTML(newAST: {program: PostHTMLNode}): string {
|
|
20
17
|
return render(newAST.program, {
|
|
21
18
|
closingSingleTag: 'slash',
|
|
22
19
|
});
|
|
@@ -24,24 +21,24 @@ function renderHTML(newAST: {|program: PostHTMLNode|}): string {
|
|
|
24
21
|
|
|
25
22
|
async function runTestTransform(
|
|
26
23
|
code: string,
|
|
27
|
-
options: {
|
|
28
|
-
shouldScopeHoist: boolean
|
|
29
|
-
supportsEsmodules: boolean
|
|
30
|
-
hmrOptions: PluginOptions['hmrOptions']
|
|
31
|
-
|
|
24
|
+
options: {
|
|
25
|
+
shouldScopeHoist: boolean;
|
|
26
|
+
supportsEsmodules: boolean;
|
|
27
|
+
hmrOptions: PluginOptions['hmrOptions'];
|
|
28
|
+
} = {
|
|
32
29
|
shouldScopeHoist: true,
|
|
33
30
|
supportsEsmodules: true,
|
|
34
31
|
hmrOptions: null,
|
|
35
32
|
},
|
|
36
33
|
) {
|
|
37
|
-
const dependencies = [];
|
|
34
|
+
const dependencies: Array<any> = [];
|
|
38
35
|
let newAST = null;
|
|
39
36
|
const asset = {
|
|
40
37
|
getAST: () => parseHTML(code, true),
|
|
41
|
-
setAST: (n) => {
|
|
38
|
+
setAST: (n: any) => {
|
|
42
39
|
newAST = n;
|
|
43
40
|
},
|
|
44
|
-
addURLDependency(url, opts) {
|
|
41
|
+
addURLDependency(url: string, opts: Partial<DependencyOptions>) {
|
|
45
42
|
dependencies.push({url, opts});
|
|
46
43
|
return `dependency-id::${url}`;
|
|
47
44
|
},
|
|
@@ -53,34 +50,31 @@ async function runTestTransform(
|
|
|
53
50
|
return options.supportsEsmodules;
|
|
54
51
|
},
|
|
55
52
|
},
|
|
56
|
-
addDependency(specifier, specifierType) {
|
|
53
|
+
addDependency(specifier: DependencyOptions, specifierType: undefined) {
|
|
57
54
|
dependencies.push({specifier, specifierType});
|
|
58
55
|
return 'dependency-id';
|
|
59
56
|
},
|
|
60
|
-
};
|
|
57
|
+
} as const;
|
|
61
58
|
|
|
62
59
|
const transformInput = {
|
|
63
60
|
asset,
|
|
64
61
|
options: {
|
|
65
62
|
hmrOptions: options.hmrOptions,
|
|
66
63
|
},
|
|
67
|
-
};
|
|
68
|
-
// $FlowFixMe
|
|
64
|
+
} as const;
|
|
69
65
|
const transformResult = await transformerOpts.transform(transformInput);
|
|
70
66
|
|
|
71
|
-
// $FlowFixMe
|
|
72
67
|
const outputCode = renderHTML(newAST);
|
|
73
68
|
|
|
74
69
|
return {dependencies, newAST, outputCode, transformResult, inputAsset: asset};
|
|
75
70
|
}
|
|
76
71
|
|
|
77
|
-
function normalizeDependencies(dependencies) {
|
|
78
|
-
return dependencies.map((dependency) => ({
|
|
72
|
+
function normalizeDependencies(dependencies: any) {
|
|
73
|
+
return dependencies.map((dependency: any) => ({
|
|
79
74
|
...dependency,
|
|
80
75
|
opts: {
|
|
81
76
|
...dependency.opts,
|
|
82
77
|
env: {
|
|
83
|
-
// $FlowFixMe
|
|
84
78
|
...dependency.opts.env,
|
|
85
79
|
loc: null,
|
|
86
80
|
},
|
|
@@ -88,9 +82,8 @@ function normalizeDependencies(dependencies) {
|
|
|
88
82
|
}));
|
|
89
83
|
}
|
|
90
84
|
|
|
91
|
-
function normalizeAssets(assets) {
|
|
92
|
-
return assets.map((asset) => {
|
|
93
|
-
// $FlowFixMe
|
|
85
|
+
function normalizeAssets(assets: any) {
|
|
86
|
+
return assets.map((asset: any) => {
|
|
94
87
|
return {
|
|
95
88
|
...asset,
|
|
96
89
|
env: null,
|
|
@@ -189,7 +182,7 @@ describe('HTMLTransformer', () => {
|
|
|
189
182
|
sourceType: 'script',
|
|
190
183
|
},
|
|
191
184
|
priority: 'parallel',
|
|
192
|
-
};
|
|
185
|
+
} as const;
|
|
193
186
|
assert.deepEqual(normalizeDependencies(dependencies), [
|
|
194
187
|
{
|
|
195
188
|
url: 'input1.js',
|
|
@@ -358,4 +351,25 @@ describe('HTMLTransformer', () => {
|
|
|
358
351
|
},
|
|
359
352
|
]);
|
|
360
353
|
});
|
|
354
|
+
|
|
355
|
+
it('transforms simple inline script with data-atlaspack-isolated', async () => {
|
|
356
|
+
const code = `
|
|
357
|
+
<html>
|
|
358
|
+
<body>
|
|
359
|
+
<script data-atlaspack-isolated>console.log('blah'); require('path');</script>
|
|
360
|
+
</body>
|
|
361
|
+
</html>
|
|
362
|
+
`;
|
|
363
|
+
const {transformResult, inputAsset} = await runTestTransform(code);
|
|
364
|
+
assert(transformResult.includes(inputAsset));
|
|
365
|
+
const assets = normalizeAssets(transformResult);
|
|
366
|
+
assert.deepEqual(assets[1], {
|
|
367
|
+
type: 'js',
|
|
368
|
+
content: "console.log('blah'); require('path');",
|
|
369
|
+
uniqueKey: 'a8a37984d2e520b9',
|
|
370
|
+
bundleBehavior: 'inlineIsolated',
|
|
371
|
+
env: null,
|
|
372
|
+
meta: null,
|
|
373
|
+
});
|
|
374
|
+
});
|
|
361
375
|
});
|
package/tsconfig.json
ADDED