@netlify/edge-bundler 14.9.12 → 14.9.13
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.
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { Parser } from 'acorn';
|
|
2
|
-
import * as walk from 'acorn-walk';
|
|
3
2
|
import { tsPlugin } from '@sveltejs/acorn-typescript';
|
|
4
|
-
const acorn = Parser.extend(tsPlugin());
|
|
3
|
+
const acorn = Parser.extend(tsPlugin({ jsx: true }));
|
|
5
4
|
/**
|
|
6
5
|
* Given source code rewrites import assert into import with
|
|
7
6
|
*/
|
|
@@ -14,32 +13,13 @@ export function rewriteSourceImportAssertions(source) {
|
|
|
14
13
|
const parsedAST = acorn.parse(source, {
|
|
15
14
|
ecmaVersion: 'latest',
|
|
16
15
|
sourceType: 'module',
|
|
16
|
+
locations: true,
|
|
17
17
|
});
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
modified = modified.replace(statement, newStatement);
|
|
24
|
-
}
|
|
25
|
-
},
|
|
26
|
-
ImportExpression(node) {
|
|
27
|
-
const statement = source.slice(node.source.end, node.end);
|
|
28
|
-
if (statement.includes('assert')) {
|
|
29
|
-
const newStatement = statement.replace('assert', 'with');
|
|
30
|
-
modified = modified.replace(statement, newStatement);
|
|
31
|
-
}
|
|
32
|
-
},
|
|
33
|
-
ExportNamedDeclaration(node) {
|
|
34
|
-
if (!node.source)
|
|
35
|
-
return;
|
|
36
|
-
const statement = source.slice(node.source.end, node.end);
|
|
37
|
-
if (statement.includes('assert')) {
|
|
38
|
-
const newStatement = statement.replace('assert', 'with');
|
|
39
|
-
modified = modified.replace(statement, newStatement);
|
|
40
|
-
}
|
|
41
|
-
},
|
|
42
|
-
});
|
|
18
|
+
const statements = collectImportAssertions(source, parsedAST.body);
|
|
19
|
+
// Bulk replacement of import assertions
|
|
20
|
+
for (const statement of statements.sort((a, b) => b.start - a.start)) {
|
|
21
|
+
modified = `${modified.slice(0, statement.start)}${statement.text}${modified.slice(statement.end)}`;
|
|
22
|
+
}
|
|
43
23
|
return modified;
|
|
44
24
|
}
|
|
45
25
|
catch (error) {
|
|
@@ -49,3 +29,41 @@ export function rewriteSourceImportAssertions(source) {
|
|
|
49
29
|
throw error;
|
|
50
30
|
}
|
|
51
31
|
}
|
|
32
|
+
function collectImportAssertions(source, node) {
|
|
33
|
+
const collectedNodes = [];
|
|
34
|
+
if (Array.isArray(node)) {
|
|
35
|
+
return node.flatMap((n) => collectImportAssertions(source, n));
|
|
36
|
+
}
|
|
37
|
+
// Capture all import assertion statements
|
|
38
|
+
const assertionNodeTypes = ['ImportDeclaration', 'ImportExpression', 'ExportAllDeclaration', 'ExportNamedDeclaration'];
|
|
39
|
+
if (assertionNodeTypes.includes(node.type)) {
|
|
40
|
+
const parsedImportNode = parseImportAssertion(source, node);
|
|
41
|
+
if (parsedImportNode !== undefined) {
|
|
42
|
+
return [parsedImportNode];
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
// Fallthrough tree traversal + support for dynamic imports and JSX syntax
|
|
46
|
+
for (const [key, value] of Object.entries(node)) {
|
|
47
|
+
if (['loc', 'typeName'].includes(key))
|
|
48
|
+
continue;
|
|
49
|
+
if (value === null)
|
|
50
|
+
continue;
|
|
51
|
+
if (typeof value === 'object') {
|
|
52
|
+
const childNodes = collectImportAssertions(source, value);
|
|
53
|
+
collectedNodes.push(...childNodes);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
return collectedNodes;
|
|
57
|
+
}
|
|
58
|
+
function parseImportAssertion(source, node) {
|
|
59
|
+
if (!node.source)
|
|
60
|
+
return undefined;
|
|
61
|
+
const statement = source.slice(node.source.end, node.end);
|
|
62
|
+
if (!statement.includes('assert'))
|
|
63
|
+
return undefined;
|
|
64
|
+
return {
|
|
65
|
+
start: node.source.end,
|
|
66
|
+
end: node.end,
|
|
67
|
+
text: statement.replace('assert', 'with'),
|
|
68
|
+
};
|
|
69
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@netlify/edge-bundler",
|
|
3
|
-
"version": "14.9.
|
|
3
|
+
"version": "14.9.13",
|
|
4
4
|
"description": "Intelligently prepare Netlify Edge Functions for deployment",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/node/index.js",
|
|
@@ -61,7 +61,6 @@
|
|
|
61
61
|
"@import-maps/resolve": "^2.0.0",
|
|
62
62
|
"@sveltejs/acorn-typescript": "^1.0.9",
|
|
63
63
|
"acorn": "^8.15.0",
|
|
64
|
-
"acorn-walk": "^8.3.4",
|
|
65
64
|
"ajv": "^8.11.2",
|
|
66
65
|
"ajv-errors": "^3.0.0",
|
|
67
66
|
"better-ajv-errors": "^1.2.0",
|
|
@@ -82,5 +81,5 @@
|
|
|
82
81
|
"urlpattern-polyfill": "8.0.2",
|
|
83
82
|
"uuid": "^11.0.0"
|
|
84
83
|
},
|
|
85
|
-
"gitHead": "
|
|
84
|
+
"gitHead": "11b6510b21a98c5948bd8b7360770a1a6855bc64"
|
|
86
85
|
}
|