@danielx/civet 0.7.7 → 0.7.9
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/README.md +7 -49
- package/dist/astro.d.mts +1 -0
- package/dist/astro.d.ts +1 -0
- package/dist/astro.js +16 -8
- package/dist/browser.js +221 -122
- package/dist/config.js +6 -2
- package/dist/esbuild.d.mts +1 -0
- package/dist/esbuild.d.ts +1 -0
- package/dist/esbuild.js +16 -8
- package/dist/main.js +221 -122
- package/dist/main.mjs +221 -122
- package/dist/rollup.d.mts +1 -0
- package/dist/rollup.d.ts +1 -0
- package/dist/rollup.js +16 -8
- package/dist/types.d.ts +9 -6
- package/dist/unplugin-shared.mjs +16 -8
- package/dist/unplugin.d.mts +4 -1
- package/dist/unplugin.d.ts +4 -1
- package/dist/unplugin.js +16 -8
- package/dist/vite.d.mts +1 -0
- package/dist/vite.d.ts +1 -0
- package/dist/vite.js +16 -8
- package/dist/webpack.d.mts +1 -0
- package/dist/webpack.d.ts +1 -0
- package/dist/webpack.js +16 -8
- package/package.json +1 -1
package/dist/esbuild.js
CHANGED
|
@@ -37,6 +37,7 @@ module.exports = __toCommonJS(esbuild_exports);
|
|
|
37
37
|
// src/index.ts
|
|
38
38
|
var import_unplugin = require("unplugin");
|
|
39
39
|
var import_civet = __toESM(require("@danielx/civet"));
|
|
40
|
+
var import_config = require("@danielx/civet/config");
|
|
40
41
|
var import_ts_diagnostic = require("@danielx/civet/ts-diagnostic");
|
|
41
42
|
var fs = __toESM(require("fs"));
|
|
42
43
|
var import_path = __toESM(require("path"));
|
|
@@ -90,6 +91,7 @@ var rawPlugin = (options = {}, meta) => {
|
|
|
90
91
|
options.emitDeclaration = options.dts;
|
|
91
92
|
if (options.js)
|
|
92
93
|
options.ts = "civet";
|
|
94
|
+
let compileOptions = {};
|
|
93
95
|
const transformTS = options.emitDeclaration || options.typecheck;
|
|
94
96
|
const outExt = options.outputExtension ?? (options.ts === "preserve" ? ".tsx" : ".jsx");
|
|
95
97
|
const implicitExtension = options.implicitExtension ?? true;
|
|
@@ -112,12 +114,20 @@ var rawPlugin = (options = {}, meta) => {
|
|
|
112
114
|
async buildStart() {
|
|
113
115
|
if (transformTS || options.ts === "tsc") {
|
|
114
116
|
const ts = await tsPromise;
|
|
115
|
-
const
|
|
116
|
-
if (
|
|
117
|
+
const civetConfigPath = "config" in options ? options.config : await (0, import_config.findInDir)(process.cwd());
|
|
118
|
+
if (civetConfigPath) {
|
|
119
|
+
compileOptions = await (0, import_config.loadConfig)(civetConfigPath);
|
|
120
|
+
}
|
|
121
|
+
compileOptions.parseOptions = {
|
|
122
|
+
...compileOptions.parseOptions,
|
|
123
|
+
...options.parseOptions
|
|
124
|
+
};
|
|
125
|
+
const tsConfigPath = ts.findConfigFile(process.cwd(), ts.sys.fileExists);
|
|
126
|
+
if (!tsConfigPath) {
|
|
117
127
|
throw new Error("Could not find 'tsconfig.json'");
|
|
118
128
|
}
|
|
119
129
|
const { config, error } = ts.readConfigFile(
|
|
120
|
-
|
|
130
|
+
tsConfigPath,
|
|
121
131
|
ts.sys.readFile
|
|
122
132
|
);
|
|
123
133
|
if (error) {
|
|
@@ -164,9 +174,9 @@ var rawPlugin = (options = {}, meta) => {
|
|
|
164
174
|
encoding
|
|
165
175
|
});
|
|
166
176
|
const compiledTS = import_civet.default.compile(rawCivetSource, {
|
|
177
|
+
...compileOptions,
|
|
167
178
|
filename,
|
|
168
179
|
js: false,
|
|
169
|
-
comptime: Boolean(options.comptime),
|
|
170
180
|
sync: true
|
|
171
181
|
// TS readFile API seems to need to be synchronous
|
|
172
182
|
});
|
|
@@ -314,11 +324,9 @@ var rawPlugin = (options = {}, meta) => {
|
|
|
314
324
|
this.addWatchFile(filename);
|
|
315
325
|
let compiled;
|
|
316
326
|
const civetOptions = {
|
|
327
|
+
...compileOptions,
|
|
317
328
|
filename: id,
|
|
318
|
-
sourceMap: true
|
|
319
|
-
parseOptions: {
|
|
320
|
-
comptime: Boolean(options.comptime)
|
|
321
|
-
}
|
|
329
|
+
sourceMap: true
|
|
322
330
|
};
|
|
323
331
|
if (options.ts === "civet" && !transformTS) {
|
|
324
332
|
compiled = await import_civet.default.compile(rawCivetSource, {
|
package/dist/main.js
CHANGED
|
@@ -550,6 +550,7 @@ __export(lib_exports, {
|
|
|
550
550
|
processForInOf: () => processForInOf,
|
|
551
551
|
processProgram: () => processProgram,
|
|
552
552
|
processProgramAsync: () => processProgramAsync,
|
|
553
|
+
processTryBlock: () => processTryBlock,
|
|
553
554
|
processUnaryExpression: () => processUnaryExpression,
|
|
554
555
|
quoteString: () => quoteString,
|
|
555
556
|
reorderBindingRestProperty: () => reorderBindingRestProperty,
|
|
@@ -1571,7 +1572,6 @@ function isExit(node) {
|
|
|
1571
1572
|
if (!(node != null)) {
|
|
1572
1573
|
return false;
|
|
1573
1574
|
}
|
|
1574
|
-
let ref2;
|
|
1575
1575
|
switch (node.type) {
|
|
1576
1576
|
case "ReturnStatement":
|
|
1577
1577
|
case "ThrowStatement":
|
|
@@ -1583,13 +1583,10 @@ function isExit(node) {
|
|
|
1583
1583
|
return isExit(node.then) && isExit(node.else?.block);
|
|
1584
1584
|
}
|
|
1585
1585
|
case "BlockStatement": {
|
|
1586
|
-
return
|
|
1586
|
+
return node.expressions.some((s) => isExit(s[1]));
|
|
1587
1587
|
}
|
|
1588
1588
|
case "IterationStatement": {
|
|
1589
|
-
return node.condition?.type === "ParenthesizedExpression" && node.condition.expression?.type === "Literal" && node.condition.expression?.raw === "true" && gatherRecursiveWithinFunction(
|
|
1590
|
-
node.block,
|
|
1591
|
-
({ type }) => type === "BreakStatement"
|
|
1592
|
-
).length === 0;
|
|
1589
|
+
return node.condition?.type === "ParenthesizedExpression" && node.condition.expression?.type === "Literal" && node.condition.expression?.raw === "true" && gatherRecursiveWithinFunction(node.block, ($) => $.type === "BreakStatement").length === 0;
|
|
1593
1590
|
}
|
|
1594
1591
|
default: {
|
|
1595
1592
|
return false;
|
|
@@ -1890,8 +1887,8 @@ function updateParentPointers(node, parent, depth = 1) {
|
|
|
1890
1887
|
node.parent = parent;
|
|
1891
1888
|
}
|
|
1892
1889
|
if (depth && isParent(node)) {
|
|
1893
|
-
for (let
|
|
1894
|
-
const child =
|
|
1890
|
+
for (let ref2 = node.children, i3 = 0, len3 = ref2.length; i3 < len3; i3++) {
|
|
1891
|
+
const child = ref2[i3];
|
|
1895
1892
|
updateParentPointers(child, node, depth - 1);
|
|
1896
1893
|
}
|
|
1897
1894
|
}
|
|
@@ -2963,6 +2960,10 @@ function aggregateDuplicateBindings(bindings) {
|
|
|
2963
2960
|
const propsGroupedByName = /* @__PURE__ */ new Map();
|
|
2964
2961
|
for (const p of props) {
|
|
2965
2962
|
const { name, value } = p;
|
|
2963
|
+
let m;
|
|
2964
|
+
if (m = value?.type, m === "ArrayBindingPattern" || m === "ObjectBindingPattern") {
|
|
2965
|
+
continue;
|
|
2966
|
+
}
|
|
2966
2967
|
const key = value?.name || name?.name || name;
|
|
2967
2968
|
if (propsGroupedByName.has(key)) {
|
|
2968
2969
|
propsGroupedByName.get(key).push(p);
|
|
@@ -3211,7 +3212,7 @@ function processDeclarationConditionStatement(s) {
|
|
|
3211
3212
|
return;
|
|
3212
3213
|
}
|
|
3213
3214
|
let { expression } = condition;
|
|
3214
|
-
if (typeof expression === "object" &&
|
|
3215
|
+
if (expression && typeof expression === "object" && "type" in expression && expression.type === "UnaryExpression" && "children" in expression && Array.isArray(expression.children) && len2(expression.children, 2) && expression.children[0] === "!" && typeof expression.children[1] === "object" && expression.children[1] != null && "type" in expression.children[1] && expression.children[1].type === "ParenthesizedExpression" && "expression" in expression.children[1]) {
|
|
3215
3216
|
const { type: type1, children: [, { type: type2, expression: expression2 }] } = expression;
|
|
3216
3217
|
const type = [type1, type2];
|
|
3217
3218
|
expression = expression2;
|
|
@@ -3228,40 +3229,99 @@ function processDeclarationConditionStatement(s) {
|
|
|
3228
3229
|
}
|
|
3229
3230
|
});
|
|
3230
3231
|
if (conditions.length) {
|
|
3231
|
-
|
|
3232
|
-
|
|
3233
|
-
|
|
3234
|
-
|
|
3235
|
-
|
|
3232
|
+
if (s.negated) {
|
|
3233
|
+
let m;
|
|
3234
|
+
if (!(m = condition.expression, typeof m === "object" && m != null && "type" in m && m.type === "UnaryExpression" && "children" in m && Array.isArray(m.children) && len2(m.children, 2) && m.children[0] === "!" && typeof m.children[1] === "object" && m.children[1] != null && "type" in m.children[1] && m.children[1].type === "ParenthesizedExpression")) {
|
|
3235
|
+
console.log(condition.expression);
|
|
3236
|
+
throw new Error("Unsupported negated condition");
|
|
3237
|
+
}
|
|
3238
|
+
const { children } = condition.expression.children[1];
|
|
3239
|
+
const close = children.pop();
|
|
3240
|
+
conditions.forEach((c) => {
|
|
3241
|
+
return children.push(" && ", c);
|
|
3242
|
+
});
|
|
3243
|
+
children.push(close);
|
|
3244
|
+
} else {
|
|
3245
|
+
condition.children.unshift("(");
|
|
3246
|
+
conditions.forEach((c) => {
|
|
3247
|
+
return condition.children.push(" && ", c);
|
|
3248
|
+
});
|
|
3249
|
+
condition.children.push(")");
|
|
3250
|
+
}
|
|
3236
3251
|
}
|
|
3237
3252
|
}
|
|
3253
|
+
const { blockPrefix } = condition.expression;
|
|
3254
|
+
if (s.negated && blockPrefix && (s.type === "IfStatement" && isExit(s.then) || s.type === "IterationStatement")) {
|
|
3255
|
+
const { ancestor, child } = findAncestor(
|
|
3256
|
+
s,
|
|
3257
|
+
(a) => a.type === "BlockStatement"
|
|
3258
|
+
);
|
|
3259
|
+
if (!(ancestor != null)) {
|
|
3260
|
+
throw new Error("Couldn't find block for postfix declaration");
|
|
3261
|
+
}
|
|
3262
|
+
const index = findChildIndex(ancestor.expressions, child);
|
|
3263
|
+
if (index < 0) {
|
|
3264
|
+
throw new Error("Couldn't find where in block to put postfix declaration");
|
|
3265
|
+
}
|
|
3266
|
+
ancestor.expressions.splice(index + 1, 0, ...blockPrefix);
|
|
3267
|
+
updateParentPointers(ancestor);
|
|
3268
|
+
braceBlock(ancestor);
|
|
3269
|
+
let ref1;
|
|
3270
|
+
switch (s.type) {
|
|
3271
|
+
case "IfStatement": {
|
|
3272
|
+
if (ref1 = s.else?.block) {
|
|
3273
|
+
const elseBlock = ref1;
|
|
3274
|
+
if (elseBlock.bare && !elseBlock.semicolon) {
|
|
3275
|
+
elseBlock.children.push(elseBlock.semicolon = ";");
|
|
3276
|
+
}
|
|
3277
|
+
ancestor.expressions.splice(index + 1 + blockPrefix.length, 0, ["", elseBlock]);
|
|
3278
|
+
s.children = s.children.filter((a1) => a1 !== s.else);
|
|
3279
|
+
s.else = void 0;
|
|
3280
|
+
}
|
|
3281
|
+
const block = s.then;
|
|
3282
|
+
if (block.bare && !block.semicolon) {
|
|
3283
|
+
block.children.push(block.semicolon = ";");
|
|
3284
|
+
}
|
|
3285
|
+
;
|
|
3286
|
+
break;
|
|
3287
|
+
}
|
|
3288
|
+
}
|
|
3289
|
+
return;
|
|
3290
|
+
}
|
|
3238
3291
|
switch (s.type) {
|
|
3239
3292
|
case "IfStatement": {
|
|
3240
3293
|
const { else: e } = s;
|
|
3241
|
-
|
|
3242
|
-
|
|
3243
|
-
|
|
3244
|
-
|
|
3245
|
-
|
|
3246
|
-
|
|
3247
|
-
return block;
|
|
3248
|
-
} else {
|
|
3249
|
-
return c;
|
|
3294
|
+
if (s.negated) {
|
|
3295
|
+
if (e != null) {
|
|
3296
|
+
const block = blockWithPrefix(blockPrefix, e.block);
|
|
3297
|
+
e.children = e.children.map(($1) => $1 === e.block ? block : $1);
|
|
3298
|
+
e.block = block;
|
|
3299
|
+
updateParentPointers(e);
|
|
3250
3300
|
}
|
|
3251
|
-
}
|
|
3252
|
-
|
|
3253
|
-
|
|
3301
|
+
} else {
|
|
3302
|
+
const block = blockWithPrefix(blockPrefix, s.then);
|
|
3303
|
+
if (block.bare && e && !block.semicolon) {
|
|
3304
|
+
block.children.push(block.semicolon = ";");
|
|
3305
|
+
}
|
|
3306
|
+
s.children = s.children.map(($2) => $2 === s.then ? block : $2);
|
|
3307
|
+
s.then = block;
|
|
3308
|
+
updateParentPointers(s);
|
|
3309
|
+
}
|
|
3310
|
+
;
|
|
3254
3311
|
break;
|
|
3255
3312
|
}
|
|
3256
3313
|
case "IterationStatement": {
|
|
3314
|
+
if (!blockPrefix) {
|
|
3315
|
+
return;
|
|
3316
|
+
}
|
|
3257
3317
|
const { children, block } = s;
|
|
3258
|
-
const newBlock = blockWithPrefix(
|
|
3259
|
-
s.children = children.map((
|
|
3260
|
-
updateParentPointers(
|
|
3318
|
+
const newBlock = blockWithPrefix(blockPrefix, block);
|
|
3319
|
+
s.children = children.map(($3) => $3 === block ? newBlock : $3);
|
|
3320
|
+
updateParentPointers(s);
|
|
3261
3321
|
break;
|
|
3262
3322
|
}
|
|
3263
3323
|
case "SwitchStatement": {
|
|
3264
|
-
const {
|
|
3324
|
+
const { ref: ref2, statementDeclaration } = condition.expression;
|
|
3265
3325
|
if (!blockPrefix) {
|
|
3266
3326
|
return;
|
|
3267
3327
|
}
|
|
@@ -3284,7 +3344,7 @@ function processDeclarationConditionStatement(s) {
|
|
|
3284
3344
|
const block = makeEmptyBlock();
|
|
3285
3345
|
replaceBlockExpression(s.parent, s, block);
|
|
3286
3346
|
block.expressions.push(["", s]);
|
|
3287
|
-
s.children.splice(s.children.findIndex(($
|
|
3347
|
+
s.children.splice(s.children.findIndex(($4) => $4.token === "switch"), 0, blockPrefix);
|
|
3288
3348
|
s.parent = block;
|
|
3289
3349
|
} else {
|
|
3290
3350
|
const block = blockWithPrefix([["", [{
|
|
@@ -3314,20 +3374,20 @@ function dynamizeImportDeclaration(decl) {
|
|
|
3314
3374
|
const { imports } = decl;
|
|
3315
3375
|
let { star, binding, specifiers } = imports;
|
|
3316
3376
|
const justDefault = binding && !specifiers && !star;
|
|
3317
|
-
let
|
|
3377
|
+
let ref2;
|
|
3318
3378
|
{
|
|
3319
3379
|
if (binding) {
|
|
3320
3380
|
if (specifiers) {
|
|
3321
|
-
|
|
3381
|
+
ref2 = makeRef();
|
|
3322
3382
|
} else {
|
|
3323
|
-
|
|
3383
|
+
ref2 = binding;
|
|
3324
3384
|
}
|
|
3325
3385
|
} else {
|
|
3326
|
-
|
|
3386
|
+
ref2 = convertNamedImportsToObject(imports, true);
|
|
3327
3387
|
}
|
|
3328
3388
|
}
|
|
3329
3389
|
;
|
|
3330
|
-
const pattern =
|
|
3390
|
+
const pattern = ref2;
|
|
3331
3391
|
const c = "const";
|
|
3332
3392
|
const expression = [
|
|
3333
3393
|
justDefault ? "(" : void 0,
|
|
@@ -4763,6 +4823,67 @@ function handleThisPrivateShorthands(value) {
|
|
|
4763
4823
|
}
|
|
4764
4824
|
return [value, value.thisShorthand];
|
|
4765
4825
|
}
|
|
4826
|
+
function processTryBlock($0) {
|
|
4827
|
+
let [t, , b, c, e, f] = $0;
|
|
4828
|
+
if (!c && (e || !f)) {
|
|
4829
|
+
const emptyCatchBlock = makeEmptyBlock();
|
|
4830
|
+
c = {
|
|
4831
|
+
type: "CatchClause",
|
|
4832
|
+
children: [" ", "catch(e) ", emptyCatchBlock],
|
|
4833
|
+
block: emptyCatchBlock
|
|
4834
|
+
};
|
|
4835
|
+
}
|
|
4836
|
+
let hoistDec;
|
|
4837
|
+
if (e) {
|
|
4838
|
+
c = c;
|
|
4839
|
+
const ok = makeRef("ok");
|
|
4840
|
+
hoistDec = {
|
|
4841
|
+
type: "Declaration",
|
|
4842
|
+
children: ["let ", ok, " = true"],
|
|
4843
|
+
names: []
|
|
4844
|
+
};
|
|
4845
|
+
replaceNode(
|
|
4846
|
+
c.block,
|
|
4847
|
+
blockWithPrefix([["", "ok = false"]], c.block),
|
|
4848
|
+
c
|
|
4849
|
+
);
|
|
4850
|
+
const condition = {
|
|
4851
|
+
type: "ParenthesizedExpression",
|
|
4852
|
+
children: ["(", ok, ")"],
|
|
4853
|
+
expression: ok
|
|
4854
|
+
};
|
|
4855
|
+
const i = makeNode({
|
|
4856
|
+
type: "IfStatement",
|
|
4857
|
+
children: ["if", condition, e.block],
|
|
4858
|
+
condition,
|
|
4859
|
+
then: e.block,
|
|
4860
|
+
else: void 0
|
|
4861
|
+
});
|
|
4862
|
+
if (!f) {
|
|
4863
|
+
const emptyFinallyBlock = makeEmptyBlock();
|
|
4864
|
+
f = {
|
|
4865
|
+
type: "FinallyClause",
|
|
4866
|
+
children: [" ", "finally ", emptyFinallyBlock],
|
|
4867
|
+
block: emptyFinallyBlock
|
|
4868
|
+
};
|
|
4869
|
+
}
|
|
4870
|
+
replaceNode(
|
|
4871
|
+
f.block,
|
|
4872
|
+
blockWithPrefix([["", i]], f.block),
|
|
4873
|
+
f
|
|
4874
|
+
);
|
|
4875
|
+
}
|
|
4876
|
+
const blocks = [b];
|
|
4877
|
+
if (c) {
|
|
4878
|
+
blocks.push(c.block);
|
|
4879
|
+
}
|
|
4880
|
+
return {
|
|
4881
|
+
type: "TryStatement",
|
|
4882
|
+
blocks,
|
|
4883
|
+
children: [t, b, c, f],
|
|
4884
|
+
hoistDec
|
|
4885
|
+
};
|
|
4886
|
+
}
|
|
4766
4887
|
function processCallMemberExpression(node) {
|
|
4767
4888
|
const { children } = node;
|
|
4768
4889
|
if (Array.isArray(children) && children.length >= 2 && typeof children[0] === "object" && children[0] != null && "parenthesizedOp" in children[0] && typeof children[0].parenthesizedOp === "object" && children[0].parenthesizedOp != null && "token" in children[0].parenthesizedOp && typeof children[1] === "object" && children[1] != null && "type" in children[1] && children[1].type === "Call") {
|
|
@@ -5504,25 +5625,29 @@ function processStatementExpressions(statements) {
|
|
|
5504
5625
|
}
|
|
5505
5626
|
function processNegativeIndexAccess(statements) {
|
|
5506
5627
|
gatherRecursiveAll(statements, (n) => n.type === "NegativeIndex").forEach((exp) => {
|
|
5507
|
-
const {
|
|
5508
|
-
|
|
5628
|
+
const { children } = exp.parent;
|
|
5629
|
+
let start = 0;
|
|
5630
|
+
while (start < children.length && isWhitespaceOrEmpty(children[start])) {
|
|
5631
|
+
start++;
|
|
5632
|
+
}
|
|
5633
|
+
const index = children.indexOf(exp);
|
|
5509
5634
|
let ref, subexp;
|
|
5510
|
-
if (index === 1) {
|
|
5511
|
-
const child =
|
|
5635
|
+
if (index === start + 1) {
|
|
5636
|
+
const child = children[start];
|
|
5512
5637
|
ref = maybeRef(child);
|
|
5513
5638
|
if (ref !== child) {
|
|
5514
|
-
subexp =
|
|
5639
|
+
subexp = children.splice(start, 1);
|
|
5515
5640
|
}
|
|
5516
|
-
} else if (index > 1) {
|
|
5641
|
+
} else if (index > start + 1) {
|
|
5517
5642
|
ref = makeRef();
|
|
5518
|
-
subexp =
|
|
5643
|
+
subexp = children.splice(start, index);
|
|
5519
5644
|
} else {
|
|
5520
5645
|
throw new Error("Invalid parse tree for negative index access");
|
|
5521
5646
|
}
|
|
5522
5647
|
if (subexp) {
|
|
5523
5648
|
const { hoistDec, refAssignment } = makeRefAssignment(ref, subexp);
|
|
5524
5649
|
exp.hoistDec = hoistDec;
|
|
5525
|
-
|
|
5650
|
+
children.splice(start, 0, makeLeftHandSideExpression(refAssignment));
|
|
5526
5651
|
}
|
|
5527
5652
|
return exp.len.children = [
|
|
5528
5653
|
ref,
|
|
@@ -5595,6 +5720,7 @@ function populateRefs(statements) {
|
|
|
5595
5720
|
}
|
|
5596
5721
|
function processPlaceholders(statements) {
|
|
5597
5722
|
const placeholderMap = /* @__PURE__ */ new Map();
|
|
5723
|
+
const liftedIfs = /* @__PURE__ */ new Set();
|
|
5598
5724
|
gatherRecursiveAll(statements, ($3) => $3.type === "Placeholder").forEach((_exp) => {
|
|
5599
5725
|
const exp = _exp;
|
|
5600
5726
|
let ancestor;
|
|
@@ -5615,9 +5741,15 @@ function processPlaceholders(statements) {
|
|
|
5615
5741
|
let child;
|
|
5616
5742
|
({ ancestor, child } = findAncestor(exp, (ancestor2, child2) => {
|
|
5617
5743
|
const { type } = ancestor2;
|
|
5618
|
-
|
|
5744
|
+
if (type === "IfStatement") {
|
|
5745
|
+
liftedIfs.add(ancestor2);
|
|
5746
|
+
}
|
|
5747
|
+
let m;
|
|
5748
|
+
let m1;
|
|
5749
|
+
return type === "Call" || // Block, except for if/else blocks when condition already lifted
|
|
5750
|
+
type === "BlockStatement" && !((m = ancestor2.parent, typeof m === "object" && m != null && "type" in m && m.type === "IfStatement") && liftedIfs.has(ancestor2.parent)) && !((m1 = ancestor2.parent, typeof m1 === "object" && m1 != null && "type" in m1 && m1.type === "ElseClause" && "parent" in m1 && typeof m1.parent === "object" && m1.parent != null && "type" in m1.parent && m1.parent.type === "IfStatement") && liftedIfs.has(ancestor2.parent.parent)) || type === "PipelineExpression" || // Declaration
|
|
5619
5751
|
type === "Initializer" || // Right-hand side of assignment
|
|
5620
|
-
type === "AssignmentExpression" && ancestor2
|
|
5752
|
+
type === "AssignmentExpression" && findChildIndex(ancestor2, child2) === ancestor2.children.indexOf(ancestor2.expression) || type === "ReturnStatement" || type === "YieldExpression";
|
|
5621
5753
|
}));
|
|
5622
5754
|
switch (ancestor?.type) {
|
|
5623
5755
|
case "Call": {
|
|
@@ -5985,7 +6117,7 @@ var grammar = {
|
|
|
5985
6117
|
PrimaryExpression,
|
|
5986
6118
|
ParenthesizedExpression,
|
|
5987
6119
|
Placeholder,
|
|
5988
|
-
|
|
6120
|
+
PlaceholderTypeSuffix,
|
|
5989
6121
|
ClassDeclaration,
|
|
5990
6122
|
ClassExpression,
|
|
5991
6123
|
ClassBinding,
|
|
@@ -6191,7 +6323,6 @@ var grammar = {
|
|
|
6191
6323
|
IfStatement,
|
|
6192
6324
|
ElseClause,
|
|
6193
6325
|
IfClause,
|
|
6194
|
-
UnlessClause,
|
|
6195
6326
|
IterationStatement,
|
|
6196
6327
|
_IterationStatement,
|
|
6197
6328
|
IterationExpression,
|
|
@@ -6882,7 +7013,7 @@ var $R2 = (0, import_lib3.$R)(new RegExp("(as|of|satisfies|then|when|implements|
|
|
|
6882
7013
|
var $R3 = (0, import_lib3.$R)(new RegExp("[0-9]", "suy"));
|
|
6883
7014
|
var $R4 = (0, import_lib3.$R)(new RegExp("(?!\\p{ID_Start}|[_$0-9(\\[{])", "suy"));
|
|
6884
7015
|
var $R5 = (0, import_lib3.$R)(new RegExp("[ \\t]", "suy"));
|
|
6885
|
-
var $R6 = (0, import_lib3.$R)(new RegExp("(?:\\p{ID_Continue}|[\\u200C\\u200D
|
|
7016
|
+
var $R6 = (0, import_lib3.$R)(new RegExp("(?:\\p{ID_Continue}|[\\u200C\\u200D$.#])", "suy"));
|
|
6886
7017
|
var $R7 = (0, import_lib3.$R)(new RegExp("[&=]", "suy"));
|
|
6887
7018
|
var $R8 = (0, import_lib3.$R)(new RegExp("(?=['\"`])", "suy"));
|
|
6888
7019
|
var $R9 = (0, import_lib3.$R)(new RegExp("(?=[\\/?])", "suy"));
|
|
@@ -7856,15 +7987,17 @@ var ParenthesizedExpression$0 = (0, import_lib3.$TS)((0, import_lib3.$S)(OpenPar
|
|
|
7856
7987
|
function ParenthesizedExpression(ctx, state2) {
|
|
7857
7988
|
return (0, import_lib3.$EVENT)(ctx, state2, "ParenthesizedExpression", ParenthesizedExpression$0);
|
|
7858
7989
|
}
|
|
7859
|
-
var Placeholder$0 = (0, import_lib3.$TS)((0, import_lib3.$S)(Dot, (0, import_lib3.$N)((0, import_lib3.$EXPECT)($R6, "Placeholder /(?:\\p{ID_Continue}|[\\u200C\\u200D
|
|
7990
|
+
var Placeholder$0 = (0, import_lib3.$TS)((0, import_lib3.$S)(Dot, (0, import_lib3.$N)((0, import_lib3.$EXPECT)($R6, "Placeholder /(?:\\p{ID_Continue}|[\\u200C\\u200D$.#])/")), (0, import_lib3.$E)(PlaceholderTypeSuffix)), function($skip, $loc, $0, $1, $2, $3) {
|
|
7860
7991
|
var dot = $1;
|
|
7992
|
+
var typeSuffix = $3;
|
|
7861
7993
|
return {
|
|
7862
7994
|
type: "Placeholder",
|
|
7863
7995
|
subtype: ".",
|
|
7996
|
+
typeSuffix,
|
|
7864
7997
|
children: [dot]
|
|
7865
7998
|
};
|
|
7866
7999
|
});
|
|
7867
|
-
var Placeholder$1 = (0, import_lib3.$TS)((0, import_lib3.$S)(Ampersand, (0, import_lib3.$N)((0, import_lib3.$EXPECT)($R7, "Placeholder /[&=]/")), (0, import_lib3.$E)(
|
|
8000
|
+
var Placeholder$1 = (0, import_lib3.$TS)((0, import_lib3.$S)(Ampersand, (0, import_lib3.$N)((0, import_lib3.$EXPECT)($R7, "Placeholder /[&=]/")), (0, import_lib3.$E)(PlaceholderTypeSuffix)), function($skip, $loc, $0, $1, $2, $3) {
|
|
7868
8001
|
var amp = $1;
|
|
7869
8002
|
var typeSuffix = $3;
|
|
7870
8003
|
return {
|
|
@@ -7885,11 +8018,11 @@ var Placeholder$$ = [Placeholder$0, Placeholder$1, Placeholder$2];
|
|
|
7885
8018
|
function Placeholder(ctx, state2) {
|
|
7886
8019
|
return (0, import_lib3.$EVENT_C)(ctx, state2, "Placeholder", Placeholder$$);
|
|
7887
8020
|
}
|
|
7888
|
-
var
|
|
8021
|
+
var PlaceholderTypeSuffix$0 = (0, import_lib3.$T)((0, import_lib3.$S)((0, import_lib3.$Y)((0, import_lib3.$S)((0, import_lib3.$E)(QuestionMark), Colon)), TypeSuffix), function(value) {
|
|
7889
8022
|
return value[1];
|
|
7890
8023
|
});
|
|
7891
|
-
function
|
|
7892
|
-
return (0, import_lib3.$EVENT)(ctx, state2, "
|
|
8024
|
+
function PlaceholderTypeSuffix(ctx, state2) {
|
|
8025
|
+
return (0, import_lib3.$EVENT)(ctx, state2, "PlaceholderTypeSuffix", PlaceholderTypeSuffix$0);
|
|
7893
8026
|
}
|
|
7894
8027
|
var ClassDeclaration$0 = (0, import_lib3.$TS)((0, import_lib3.$S)(ClassExpression), function($skip, $loc, $0, $1) {
|
|
7895
8028
|
if ($1.id)
|
|
@@ -8103,7 +8236,8 @@ var ClassElement$1 = (0, import_lib3.$TS)((0, import_lib3.$S)(Static, BracedBloc
|
|
|
8103
8236
|
children: $0
|
|
8104
8237
|
};
|
|
8105
8238
|
});
|
|
8106
|
-
var ClassElement
|
|
8239
|
+
var ClassElement$2 = EmptyStatement;
|
|
8240
|
+
var ClassElement$$ = [ClassElement$0, ClassElement$1, ClassElement$2];
|
|
8107
8241
|
function ClassElement(ctx, state2) {
|
|
8108
8242
|
return (0, import_lib3.$EVENT_C)(ctx, state2, "ClassElement", ClassElement$$);
|
|
8109
8243
|
}
|
|
@@ -10687,18 +10821,7 @@ var ComputedPropertyName$2 = (0, import_lib3.$TS)((0, import_lib3.$S)(InsertOpen
|
|
|
10687
10821
|
implicit: true
|
|
10688
10822
|
};
|
|
10689
10823
|
});
|
|
10690
|
-
var ComputedPropertyName
|
|
10691
|
-
var open = $2;
|
|
10692
|
-
var expression = $3;
|
|
10693
|
-
var close = $4;
|
|
10694
|
-
return {
|
|
10695
|
-
type: "ComputedPropertyName",
|
|
10696
|
-
expression,
|
|
10697
|
-
children: [open, expression, close],
|
|
10698
|
-
implicit: true
|
|
10699
|
-
};
|
|
10700
|
-
});
|
|
10701
|
-
var ComputedPropertyName$$ = [ComputedPropertyName$0, ComputedPropertyName$1, ComputedPropertyName$2, ComputedPropertyName$3];
|
|
10824
|
+
var ComputedPropertyName$$ = [ComputedPropertyName$0, ComputedPropertyName$1, ComputedPropertyName$2];
|
|
10702
10825
|
function ComputedPropertyName(ctx, state2) {
|
|
10703
10826
|
return (0, import_lib3.$EVENT_C)(ctx, state2, "ComputedPropertyName", ComputedPropertyName$$);
|
|
10704
10827
|
}
|
|
@@ -11490,9 +11613,8 @@ function PostfixStatement(ctx, state2) {
|
|
|
11490
11613
|
var _PostfixStatement$0 = ForClause;
|
|
11491
11614
|
var _PostfixStatement$1 = IfClause;
|
|
11492
11615
|
var _PostfixStatement$2 = LoopClause;
|
|
11493
|
-
var _PostfixStatement$3 =
|
|
11494
|
-
var _PostfixStatement
|
|
11495
|
-
var _PostfixStatement$$ = [_PostfixStatement$0, _PostfixStatement$1, _PostfixStatement$2, _PostfixStatement$3, _PostfixStatement$4];
|
|
11616
|
+
var _PostfixStatement$3 = WhileClause;
|
|
11617
|
+
var _PostfixStatement$$ = [_PostfixStatement$0, _PostfixStatement$1, _PostfixStatement$2, _PostfixStatement$3];
|
|
11496
11618
|
function _PostfixStatement(ctx, state2) {
|
|
11497
11619
|
return (0, import_lib3.$EVENT_C)(ctx, state2, "_PostfixStatement", _PostfixStatement$$);
|
|
11498
11620
|
}
|
|
@@ -11572,7 +11694,7 @@ var LabelledItem$$ = [LabelledItem$0, LabelledItem$1];
|
|
|
11572
11694
|
function LabelledItem(ctx, state2) {
|
|
11573
11695
|
return (0, import_lib3.$EVENT_C)(ctx, state2, "LabelledItem", LabelledItem$$);
|
|
11574
11696
|
}
|
|
11575
|
-
var IfStatement$0 = (0, import_lib3.$TS)((0, import_lib3.$S)(
|
|
11697
|
+
var IfStatement$0 = (0, import_lib3.$TS)((0, import_lib3.$S)(IfClause, BlockOrEmpty, (0, import_lib3.$E)(ElseClause)), function($skip, $loc, $0, $1, $2, $3) {
|
|
11576
11698
|
var clause = $1;
|
|
11577
11699
|
var block = $2;
|
|
11578
11700
|
var e = $3;
|
|
@@ -11580,6 +11702,7 @@ var IfStatement$0 = (0, import_lib3.$TS)((0, import_lib3.$S)((0, import_lib3.$C)
|
|
|
11580
11702
|
type: "IfStatement",
|
|
11581
11703
|
children: [...clause.children, block, e],
|
|
11582
11704
|
condition: clause.condition,
|
|
11705
|
+
negated: clause.negated,
|
|
11583
11706
|
then: block,
|
|
11584
11707
|
else: e
|
|
11585
11708
|
};
|
|
@@ -11594,33 +11717,24 @@ var ElseClause$0 = (0, import_lib3.$T)((0, import_lib3.$S)((0, import_lib3.$C)(N
|
|
|
11594
11717
|
function ElseClause(ctx, state2) {
|
|
11595
11718
|
return (0, import_lib3.$EVENT)(ctx, state2, "ElseClause", ElseClause$0);
|
|
11596
11719
|
}
|
|
11597
|
-
var IfClause$0 = (0, import_lib3.$TS)((0, import_lib3.$S)(If, Condition), function($skip, $loc, $0, $1, $2) {
|
|
11598
|
-
var
|
|
11720
|
+
var IfClause$0 = (0, import_lib3.$TS)((0, import_lib3.$S)((0, import_lib3.$C)(If, Unless), (0, import_lib3.$E)(_), Condition), function($skip, $loc, $0, $1, $2, $3) {
|
|
11721
|
+
var kind = $1;
|
|
11722
|
+
var ws = $2;
|
|
11723
|
+
var condition = $3;
|
|
11724
|
+
if (kind.negated) {
|
|
11725
|
+
kind = { ...kind, token: "if" };
|
|
11726
|
+
condition = negateCondition(condition);
|
|
11727
|
+
}
|
|
11599
11728
|
return {
|
|
11600
11729
|
type: "IfStatement",
|
|
11601
|
-
children:
|
|
11602
|
-
condition
|
|
11730
|
+
children: [kind, ws, condition],
|
|
11731
|
+
condition,
|
|
11732
|
+
negated: kind.negated
|
|
11603
11733
|
};
|
|
11604
11734
|
});
|
|
11605
11735
|
function IfClause(ctx, state2) {
|
|
11606
11736
|
return (0, import_lib3.$EVENT)(ctx, state2, "IfClause", IfClause$0);
|
|
11607
11737
|
}
|
|
11608
|
-
var UnlessClause$0 = (0, import_lib3.$TS)((0, import_lib3.$S)(Unless, Condition), function($skip, $loc, $0, $1, $2) {
|
|
11609
|
-
var kind = $1;
|
|
11610
|
-
var condition = $2;
|
|
11611
|
-
kind = { ...kind, token: "if" };
|
|
11612
|
-
kind.token += getTrimmingSpace(condition);
|
|
11613
|
-
condition = insertTrimmingSpace(condition, "");
|
|
11614
|
-
condition = negateCondition(condition);
|
|
11615
|
-
return {
|
|
11616
|
-
type: "IfStatement",
|
|
11617
|
-
children: [kind, condition],
|
|
11618
|
-
condition
|
|
11619
|
-
};
|
|
11620
|
-
});
|
|
11621
|
-
function UnlessClause(ctx, state2) {
|
|
11622
|
-
return (0, import_lib3.$EVENT)(ctx, state2, "UnlessClause", UnlessClause$0);
|
|
11623
|
-
}
|
|
11624
11738
|
var IterationStatement$0 = (0, import_lib3.$T)((0, import_lib3.$S)((0, import_lib3.$EXPECT)($R25, "IterationStatement /(?=loop|comptime|do|for|until|while)/"), _IterationStatement), function(value) {
|
|
11625
11739
|
return value[1];
|
|
11626
11740
|
});
|
|
@@ -11750,7 +11864,7 @@ var WhileClause$0 = (0, import_lib3.$TS)((0, import_lib3.$S)((0, import_lib3.$C)
|
|
|
11750
11864
|
var kind = $1;
|
|
11751
11865
|
var ws = $2;
|
|
11752
11866
|
var condition = $3;
|
|
11753
|
-
if (kind.
|
|
11867
|
+
if (kind.negated) {
|
|
11754
11868
|
kind = { ...kind, token: "while" };
|
|
11755
11869
|
condition = negateCondition(condition);
|
|
11756
11870
|
}
|
|
@@ -11758,7 +11872,8 @@ var WhileClause$0 = (0, import_lib3.$TS)((0, import_lib3.$S)((0, import_lib3.$C)
|
|
|
11758
11872
|
type: "IterationStatement",
|
|
11759
11873
|
subtype: kind.token,
|
|
11760
11874
|
children: [kind, ws, condition],
|
|
11761
|
-
condition
|
|
11875
|
+
condition,
|
|
11876
|
+
negated: kind.negated
|
|
11762
11877
|
};
|
|
11763
11878
|
});
|
|
11764
11879
|
function WhileClause(ctx, state2) {
|
|
@@ -12233,32 +12348,8 @@ var IgnoreColon$0 = (0, import_lib3.$TV)((0, import_lib3.$E)((0, import_lib3.$S)
|
|
|
12233
12348
|
function IgnoreColon(ctx, state2) {
|
|
12234
12349
|
return (0, import_lib3.$EVENT)(ctx, state2, "IgnoreColon", IgnoreColon$0);
|
|
12235
12350
|
}
|
|
12236
|
-
var TryStatement$0 = (0, import_lib3.$TS)((0, import_lib3.$S)(Try, (0, import_lib3.$N)((0, import_lib3.$EXPECT)($L15, 'TryStatement ":"')), NoPostfixBracedOrEmptyBlock, (0, import_lib3.$E)(CatchClause), (0, import_lib3.$E)(FinallyClause)), function($skip, $loc, $0, $1, $2, $3, $4, $5) {
|
|
12237
|
-
|
|
12238
|
-
var b = $3;
|
|
12239
|
-
var c = $4;
|
|
12240
|
-
var f = $5;
|
|
12241
|
-
if (!c && !f) {
|
|
12242
|
-
const emptyCatchBlock = makeEmptyBlock();
|
|
12243
|
-
c = {
|
|
12244
|
-
type: "CatchClause",
|
|
12245
|
-
children: [" catch(e) ", emptyCatchBlock],
|
|
12246
|
-
block: emptyCatchBlock
|
|
12247
|
-
};
|
|
12248
|
-
return {
|
|
12249
|
-
type: "TryStatement",
|
|
12250
|
-
blocks: [b, emptyCatchBlock],
|
|
12251
|
-
children: [t, b, c]
|
|
12252
|
-
};
|
|
12253
|
-
}
|
|
12254
|
-
const blocks = [b];
|
|
12255
|
-
if (c)
|
|
12256
|
-
blocks.push(c.block);
|
|
12257
|
-
return {
|
|
12258
|
-
type: "TryStatement",
|
|
12259
|
-
blocks,
|
|
12260
|
-
children: [t, b, c, f]
|
|
12261
|
-
};
|
|
12351
|
+
var TryStatement$0 = (0, import_lib3.$TS)((0, import_lib3.$S)(Try, (0, import_lib3.$N)((0, import_lib3.$EXPECT)($L15, 'TryStatement ":"')), NoPostfixBracedOrEmptyBlock, (0, import_lib3.$E)(CatchClause), (0, import_lib3.$E)(ElseClause), (0, import_lib3.$E)(FinallyClause)), function($skip, $loc, $0, $1, $2, $3, $4, $5, $6) {
|
|
12352
|
+
return processTryBlock($0);
|
|
12262
12353
|
});
|
|
12263
12354
|
function TryStatement(ctx, state2) {
|
|
12264
12355
|
return (0, import_lib3.$EVENT)(ctx, state2, "TryStatement", TryStatement$0);
|
|
@@ -12280,7 +12371,14 @@ var CatchBind$$ = [CatchBind$0, CatchBind$1];
|
|
|
12280
12371
|
function CatchBind(ctx, state2) {
|
|
12281
12372
|
return (0, import_lib3.$EVENT_C)(ctx, state2, "CatchBind", CatchBind$$);
|
|
12282
12373
|
}
|
|
12283
|
-
var FinallyClause$0 = (0, import_lib3.$S)((0, import_lib3.$C)(Nested, _), Finally, (0, import_lib3.$C)(BracedThenClause, BracedOrEmptyBlock))
|
|
12374
|
+
var FinallyClause$0 = (0, import_lib3.$TS)((0, import_lib3.$S)((0, import_lib3.$C)(Nested, _), Finally, (0, import_lib3.$C)(BracedThenClause, BracedOrEmptyBlock)), function($skip, $loc, $0, $1, $2, $3) {
|
|
12375
|
+
var block = $3;
|
|
12376
|
+
return {
|
|
12377
|
+
type: "FinallyClause",
|
|
12378
|
+
children: $0,
|
|
12379
|
+
block
|
|
12380
|
+
};
|
|
12381
|
+
});
|
|
12284
12382
|
function FinallyClause(ctx, state2) {
|
|
12285
12383
|
return (0, import_lib3.$EVENT)(ctx, state2, "FinallyClause", FinallyClause$0);
|
|
12286
12384
|
}
|
|
@@ -12337,7 +12435,8 @@ var DeclarationCondition$0 = (0, import_lib3.$TS)((0, import_lib3.$S)(ForbidBrac
|
|
|
12337
12435
|
return $skip;
|
|
12338
12436
|
return {
|
|
12339
12437
|
type: "DeclarationCondition",
|
|
12340
|
-
declaration
|
|
12438
|
+
declaration,
|
|
12439
|
+
children: [declaration]
|
|
12341
12440
|
};
|
|
12342
12441
|
});
|
|
12343
12442
|
function DeclarationCondition(ctx, state2) {
|
|
@@ -14137,7 +14236,7 @@ function Unless(ctx, state2) {
|
|
|
14137
14236
|
return (0, import_lib3.$EVENT)(ctx, state2, "Unless", Unless$0);
|
|
14138
14237
|
}
|
|
14139
14238
|
var Until$0 = (0, import_lib3.$TS)((0, import_lib3.$S)((0, import_lib3.$EXPECT)($L205, 'Until "until"'), NonIdContinue), function($skip, $loc, $0, $1, $2) {
|
|
14140
|
-
return { $loc, token: $1 };
|
|
14239
|
+
return { $loc, token: $1, negated: true };
|
|
14141
14240
|
});
|
|
14142
14241
|
function Until(ctx, state2) {
|
|
14143
14242
|
return (0, import_lib3.$EVENT)(ctx, state2, "Until", Until$0);
|