solid-optimizer 1.0.0-next.7 → 1.0.0-next.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 CHANGED
@@ -8,6 +8,8 @@
8
8
 
9
9
  ![A small app compiled by Solid's JSX transform alone and with solid-optimizer first. The optimized build has 1 template instead of 5, and its server HTML has 1 hydration key instead of 4.](https://github.com/lxsmnsyc/solid-optimizer/blob/main/examples/showcase/comparison.png?raw=true)
10
10
 
11
+ The website, [solid-optimizer.vercel.app](https://solid-optimizer.vercel.app), shows each pass and the benchmarks for the example apps.
12
+
11
13
  ## Install
12
14
 
13
15
  The Solid 2.0 version is published under the `next` tag. The `latest` version is for Solid 1.x, which only gets fixes now, from the [`0.x` branch](https://github.com/lxsmnsyc/solid-optimizer/tree/0.x).
@@ -140,7 +142,7 @@ Each line is a pass, a reason, how many times it happened, and the names it happ
140
142
  - `no-host` means the component has statements, and the call is not in JSX that a component or one of Solid's callbacks returns. A `<Show>` child or a `fallback` is one such place.
141
143
  - `size` means the copies would be larger than the calls.
142
144
  - `lazy`, `imported`, `nested`, and `not-a-function` mean the tag is not a component declared at the top of the same module or chunk.
143
- - A reason that starts with `copy-` is about copying a component from another module. `copy-package` means it comes from a package in `node_modules` that `optimizer.packages` does not list, `copy-cycle` means the two modules import each other, `copy-wrapper` means the component only returns a call of another component in its module, and `copy-size` means the copy was larger.
145
+ - A reason that starts with `copy-` is about copying a component from another module. `copy-package` means it comes from a package in `node_modules` that `optimizer.packages` does not list, `copy-cycle` means the component's module imports the importer back, directly or through other modules, a listed package, or a virtual module, `copy-virtual` means the copy would import a virtual module that its specifier does not reach from the importer, `copy-wrapper` means the component only returns a call of another component in its module, and `copy-size` means the copy was larger.
144
146
 
145
147
  The provider pass reports `open-component`, `open-call`, `open-new`, `open-spread`, and `open-outer` for code under the provider that it cannot see into, and `provider-value`, `provider-undefined`, and `provider-shape` for a value or provider it cannot handle. The memo pass reports `memo-reads`, `memo-read-place`, `memo-constant`, and a few more for a memo it keeps, and `signal-constant` for a signal that nothing writes but that is used other than by calling it.
146
148
 
@@ -199,7 +201,7 @@ Solid then creates one template for `<main>` instead of two.
199
201
 
200
202
  A component inlines when all of these hold:
201
203
 
202
- - It is declared once at the top level, with a capitalized name. A call through an alias, like `const Separator = SeparatorRoot`, is a call of the component it names.
204
+ - It is declared once at the top level, with a capitalized name. A call through an alias, like `const Separator = SeparatorRoot`, is a call of the component it names. So is a call through a compound component, like Kobalte's `const Dialog = Object.assign(DialogRoot, { Trigger: DialogTrigger })`: `<Dialog>` calls `DialogRoot` and `<Dialog.Trigger>` calls `DialogTrigger`, as long as nothing writes to a member of either.
203
205
  - Its parameter is one identifier that is only read as `props.name`, spread onto an element as `{...props}`, or passed to `merge()` and `omit()`. See below.
204
206
  - Its body ends in the only `return`, and that `return` returns JSX.
205
207
  - It does not use `this`, `arguments`, `super`, or `new.target`.
@@ -258,6 +258,30 @@ function isWithinScope(scope, ancestor) {
258
258
  }
259
259
  return false;
260
260
  }
261
+ /**
262
+ * Whether a parameter list holds an expression: a default value or a computed
263
+ * key, at any depth.
264
+ */
265
+ function hasParameterExpressions(params) {
266
+ for (const param of params) if (hasPatternExpression(param)) return true;
267
+ return false;
268
+ }
269
+ function hasPatternExpression(pattern) {
270
+ switch (pattern.type) {
271
+ case "AssignmentPattern": return true;
272
+ case "ObjectPattern":
273
+ for (const property of pattern.properties) if (property.type === "RestElement") {
274
+ if (hasPatternExpression(property.argument)) return true;
275
+ } else if (property.computed || hasPatternExpression(property.value)) return true;
276
+ return false;
277
+ case "ArrayPattern":
278
+ for (const element of pattern.elements) if (element && hasPatternExpression(element)) return true;
279
+ return false;
280
+ case "RestElement": return hasPatternExpression(pattern.argument);
281
+ case "TSParameterProperty": return hasPatternExpression(pattern.parameter);
282
+ default: return false;
283
+ }
284
+ }
261
285
  function exportName$1(name) {
262
286
  return name.type === "Literal" ? name.value : name.name;
263
287
  }
@@ -266,6 +290,7 @@ var Analyzer = class {
266
290
  this.scopes = /* @__PURE__ */ new Map();
267
291
  this.names = /* @__PURE__ */ new Set();
268
292
  this.pending = [];
293
+ this.bodies = /* @__PURE__ */ new Set();
269
294
  this.root = {
270
295
  node: program,
271
296
  parent: void 0,
@@ -303,7 +328,10 @@ var Analyzer = class {
303
328
  }
304
329
  declare(identifier, kind, declaration, source, imported) {
305
330
  let target = this.scope;
306
- if (kind === "var") while (!target.isFunction && target.parent) target = target.parent;
331
+ if (kind === "var") {
332
+ while (!target.isFunction && target.parent) target = target.parent;
333
+ if (this.bodies.has(target.node) && target.parent?.bindings.has(identifier.name)) target = target.parent;
334
+ }
307
335
  this.names.add(identifier.name);
308
336
  const existing = target.bindings.get(identifier.name);
309
337
  if (existing) {
@@ -399,10 +427,23 @@ var Analyzer = class {
399
427
  this.withScope(node, true, () => {
400
428
  if (node.type === "FunctionExpression" && node.id) this.declare(node.id, "other", node);
401
429
  for (const param of node.params) this.declarePattern(param, "param", node);
402
- if (node.body) {
403
- this.scopes.set(node.body, this.scope);
404
- this.visitStatements(node.body.body);
405
- }
430
+ if (node.body) this.visitBody(node.body, node.params);
431
+ });
432
+ }
433
+ /**
434
+ * Visits the block body of a function. When a parameter holds an expression,
435
+ * the body gets its own scope, so the expression cannot see the body's
436
+ * declarations.
437
+ */
438
+ visitBody(body, params) {
439
+ if (!hasParameterExpressions(params)) {
440
+ this.scopes.set(body, this.scope);
441
+ this.visitStatements(body.body);
442
+ return;
443
+ }
444
+ this.bodies.add(body);
445
+ this.withScope(body, true, () => {
446
+ this.visitStatements(body.body);
406
447
  });
407
448
  }
408
449
  visitClass(node) {
@@ -458,10 +499,8 @@ var Analyzer = class {
458
499
  case "ArrowFunctionExpression":
459
500
  this.withScope(node, true, () => {
460
501
  for (const param of node.params) this.declarePattern(param, "param", node);
461
- if (node.body.type === "BlockStatement") {
462
- this.scopes.set(node.body, this.scope);
463
- this.visitStatements(node.body.body);
464
- } else this.visit(node.body);
502
+ if (node.body.type === "BlockStatement") this.visitBody(node.body, node.params);
503
+ else this.visit(node.body);
465
504
  });
466
505
  break;
467
506
  case "ClassDeclaration":
@@ -562,13 +601,27 @@ var Analyzer = class {
562
601
  for (const child of node.children) this.visit(child);
563
602
  if (node.closingElement) this.visitJSXName(node.closingElement.name);
564
603
  break;
565
- case "TSEnumDeclaration":
566
604
  case "TSImportEqualsDeclaration":
567
605
  this.declare(node.id, "other", node);
568
606
  break;
569
- case "TSModuleDeclaration":
570
- if (node.id.type === "Identifier") this.declare(node.id, "other", node);
607
+ case "TSEnumDeclaration":
608
+ this.declare(node.id, "other", node);
609
+ if (node.declare) break;
610
+ this.withScope(node, false, () => {
611
+ for (const member of node.body.members) if (member.id.type === "Identifier") this.declare(member.id, "other", member);
612
+ for (const member of node.body.members) if (member.initializer) this.visit(member.initializer);
613
+ });
571
614
  break;
615
+ case "TSModuleDeclaration": {
616
+ let id = node.id;
617
+ while (id.type === "TSQualifiedName") id = id.left;
618
+ if (id.type === "Identifier") this.declare(id, "other", node);
619
+ const { body } = node;
620
+ if (!node.declare && body) this.withScope(node, true, () => {
621
+ this.visitStatements(body.body);
622
+ });
623
+ break;
624
+ }
572
625
  default: forEachChild(node, (child) => {
573
626
  this.visit(child);
574
627
  });
@@ -924,6 +977,16 @@ function namedImportSources(program, scopes = analyzeScopes(program)) {
924
977
  return [...sources];
925
978
  }
926
979
  /**
980
+ * The modules a module still imports once its types are stripped: the
981
+ * sources of `namedImportSources`, and imports for side effects only, like
982
+ * `import './setup'`.
983
+ */
984
+ function runtimeImportSources(program, scopes = analyzeScopes(program)) {
985
+ const sources = new Set(namedImportSources(program, scopes));
986
+ for (const statement of program.body) if (statement.type === "ImportDeclaration" && statement.importKind !== "type" && statement.specifiers.length === 0) sources.add(statement.source.value);
987
+ return [...sources];
988
+ }
989
+ /**
927
990
  * Whether the module reads one of these import bindings as a value. Scope
928
991
  * analysis skips type positions, so a binding used only in types has no
929
992
  * references.
@@ -1457,9 +1520,11 @@ var Folder = class {
1457
1520
  constructor(context) {
1458
1521
  this.context = context;
1459
1522
  this.changed = false;
1523
+ this.removed = /* @__PURE__ */ new Set();
1460
1524
  this.lookup = new ConstantTable(context.scopes, context.options).lookup;
1461
1525
  }
1462
1526
  walk(node) {
1527
+ if (this.removed.has(node)) return;
1463
1528
  forEachChild(node, (child) => {
1464
1529
  this.walk(child);
1465
1530
  });
@@ -2150,6 +2215,56 @@ var Folder = class {
2150
2215
  this.changed = true;
2151
2216
  }
2152
2217
  }
2218
+ /**
2219
+ * Removes each declaration inside a function that nothing references. The
2220
+ * references are those of the code this pass parsed, so a binding whose last
2221
+ * read this pass folds is removed in the next round.
2222
+ */
2223
+ removeUnusedDeclarations() {
2224
+ for (const scope of this.context.scopes.scopes.values()) {
2225
+ if (scope === this.context.scopes.root) continue;
2226
+ for (const binding of scope.bindings.values()) {
2227
+ const declaration = this.unusedDeclaration(binding);
2228
+ if (declaration && !this.removed.has(declaration)) {
2229
+ this.removed.add(declaration);
2230
+ this.context.s.remove(declaration.start, declaration.end);
2231
+ this.changed = true;
2232
+ }
2233
+ }
2234
+ }
2235
+ }
2236
+ /**
2237
+ * The declaration statement of `binding` when every binding it declares is
2238
+ * unused and every initializer can be skipped.
2239
+ */
2240
+ unusedDeclaration(binding) {
2241
+ if (binding.declaration.type !== "VariableDeclarator") return;
2242
+ const statement = this.context.parents.get(binding.declaration);
2243
+ if (statement?.type !== "VariableDeclaration" || statement.kind !== "const" && statement.kind !== "let" || statement.declare) return;
2244
+ const container = this.context.parents.get(statement)?.type;
2245
+ if (container !== "BlockStatement" && container !== "StaticBlock" && container !== "SwitchCase") return;
2246
+ for (const declarator of statement.declarations) {
2247
+ if (declarator.id.type !== "Identifier") return;
2248
+ const declared = binding.scope.bindings.get(declarator.id.name);
2249
+ if (!declared || declared.mutated || declared.references.length > 0) return;
2250
+ if (declarator.init && !this.isSkippableInit(declarator.init)) return;
2251
+ }
2252
+ return statement;
2253
+ }
2254
+ /**
2255
+ * Whether an unused initializer can be dropped: an expression with no side
2256
+ * effects, or a Solid call that only creates a value from such arguments.
2257
+ */
2258
+ isSkippableInit(init) {
2259
+ if (isSideEffectFree(init)) return true;
2260
+ const call = unwrap(init);
2261
+ if (call.type !== "CallExpression" || call.callee.type !== "Identifier") return false;
2262
+ const callee = this.context.scopes.references.get(call.callee);
2263
+ const identity = callee ? solidExport(callee, this.context.options) : void 0;
2264
+ if (identity === void 0 || !PURE_CALLS.has(identity) && !(PURE_VALUE_CALLS.has(identity) && isValueArgument(call))) return false;
2265
+ for (const argument of call.arguments) if (argument.type === "SpreadElement" || !isSideEffectFree(argument)) return false;
2266
+ return true;
2267
+ }
2153
2268
  replaceStatement(statement, text) {
2154
2269
  if (text === "") {
2155
2270
  this.context.s.remove(statement.start, statement.end);
@@ -2198,6 +2313,7 @@ var Folder = class {
2198
2313
  */
2199
2314
  function fold(context) {
2200
2315
  const folder = new Folder(context);
2316
+ folder.removeUnusedDeclarations();
2201
2317
  folder.walk(context.program);
2202
2318
  return folder.changed;
2203
2319
  }
@@ -3377,7 +3493,7 @@ var Inliner = class {
3377
3493
  if (init.type !== "CallExpression" || callee !== "merge" && callee !== "omit") continue;
3378
3494
  const view = this.resolveView(callee, init, param, views, args);
3379
3495
  if (view === null) continue;
3380
- const binding = scope.bindings.get(declarator.id.name);
3496
+ const binding = ((fn.body && this.context.scopes.scopes.get(fn.body)) ?? scope).bindings.get(declarator.id.name);
3381
3497
  if (!view || !binding || binding.mutated) return;
3382
3498
  views.set(binding, view);
3383
3499
  declarations.push(statement);
@@ -4279,16 +4395,82 @@ var Inliner = class {
4279
4395
  return target && target !== binding && target.scope.parent === void 0 && !target.mutated && isCapitalized(target.name) ? target : void 0;
4280
4396
  }
4281
4397
  /**
4398
+ * The parts of a compound component like Kobalte's
4399
+ * `const Dialog = Object.assign(DialogRoot, { Trigger: DialogTrigger })`,
4400
+ * or `undefined` when the binding is not one. `<Dialog>` is `<DialogRoot>`,
4401
+ * since `Object.assign` returns its first argument, and `<Dialog.Trigger>`
4402
+ * is `<DialogTrigger>` while nothing writes to a member of either.
4403
+ */
4404
+ compoundTarget(binding) {
4405
+ const { declaration } = binding;
4406
+ if (!isCapitalized(binding.name) || !isConstantDeclaration(binding, this.context.options) || declaration.type !== "VariableDeclarator" || declaration.id !== binding.identifier || !declaration.init) return;
4407
+ const init = unwrap(declaration.init);
4408
+ if (init.type !== "CallExpression" || init.optional || init.arguments.length !== 2 || !this.isObjectAssign(init.callee)) return;
4409
+ const [first, second] = init.arguments;
4410
+ if (first.type !== "Identifier" || second.type !== "ObjectExpression") return;
4411
+ const root = this.topLevelComponent(first);
4412
+ if (!root || root === binding || this.hasMemberWrite(binding) || this.hasMemberWrite(root)) return;
4413
+ const parts = /* @__PURE__ */ new Map();
4414
+ for (const property of second.properties) {
4415
+ if (property.type !== "Property" || property.kind !== "init" || property.computed || property.method || property.value.type !== "Identifier") return;
4416
+ const key = propertyKeyName(property.key);
4417
+ if (key === void 0) return;
4418
+ const part = this.topLevelComponent(property.value);
4419
+ if (part) parts.set(key, part);
4420
+ }
4421
+ return {
4422
+ root,
4423
+ parts
4424
+ };
4425
+ }
4426
+ /** Whether `callee` is the global `Object.assign`. */
4427
+ isObjectAssign(callee) {
4428
+ return callee.type === "MemberExpression" && !callee.computed && !callee.optional && callee.object.type === "Identifier" && callee.object.name === "Object" && !this.context.scopes.references.get(callee.object) && callee.property.type === "Identifier" && callee.property.name === "assign";
4429
+ }
4430
+ /** The top-level binding with a capitalized name that `reference` reads, when nothing reassigns it. */
4431
+ topLevelComponent(reference) {
4432
+ const target = this.context.scopes.references.get(reference);
4433
+ return target && target.scope.parent === void 0 && !target.mutated && isCapitalized(target.name) ? target : void 0;
4434
+ }
4435
+ /** Whether anything assigns to, updates, or deletes a member of the binding. */
4436
+ hasMemberWrite(binding) {
4437
+ for (const reference of binding.references) {
4438
+ const member = this.context.parents.get(reference);
4439
+ if (member?.type !== "MemberExpression" || member.object !== reference) continue;
4440
+ const use = this.context.parents.get(member);
4441
+ if (use?.type === "AssignmentExpression" && use.left === member || use?.type === "UpdateExpression" || use?.type === "UnaryExpression" && use.operator === "delete") return true;
4442
+ }
4443
+ return false;
4444
+ }
4445
+ /** Whether the code reads a member of the binding, like `DialogRoot.Trigger`. */
4446
+ hasMemberRead(binding) {
4447
+ for (const reference of binding.references) {
4448
+ const member = this.context.parents.get(reference);
4449
+ if ((member?.type === "MemberExpression" || member?.type === "JSXMemberExpression") && member.object === reference) return true;
4450
+ }
4451
+ return false;
4452
+ }
4453
+ /**
4282
4454
  * The statement of an alias nothing uses that `reference` is the value
4283
4455
  * of, like `const Separator = SeparatorRoot` once its tags are renamed.
4284
- * It does not keep the component, and goes away with it.
4456
+ * It does not keep the component, and goes away with it. A compound
4457
+ * component counts too, when its tags are renamed and nothing reads the
4458
+ * members `Object.assign` gave its root.
4285
4459
  */
4286
4460
  unusedAlias(reference) {
4287
- const declarator = this.context.parents.get(reference);
4461
+ let declarator = this.context.parents.get(reference);
4462
+ if (declarator?.type === "Property") declarator = this.context.parents.get(declarator);
4463
+ if (declarator?.type === "ObjectExpression" || declarator?.type === "CallExpression") {
4464
+ const call = declarator.type === "CallExpression" ? declarator : this.context.parents.get(declarator);
4465
+ declarator = call ? this.context.parents.get(call) : void 0;
4466
+ }
4288
4467
  if (declarator?.type !== "VariableDeclarator" || declarator.id.type !== "Identifier") return;
4289
4468
  const alias = this.context.scopes.root.bindings.get(declarator.id.name);
4469
+ if (alias?.declaration !== declarator || alias.references.length > 0) return;
4470
+ const compound = this.compoundTarget(alias);
4471
+ if (this.aliasTarget(alias) === void 0 && (!compound || this.hasMemberRead(compound.root))) return;
4290
4472
  const statement = this.context.parents.get(declarator);
4291
- return alias?.declaration === declarator && this.aliasTarget(alias) !== void 0 && alias.references.length === 0 && statement?.type === "VariableDeclaration" && statement.declarations.length === 1 && this.context.parents.get(statement)?.type === "Program" ? statement : void 0;
4473
+ return statement?.type === "VariableDeclaration" && statement.declarations.length === 1 && this.context.parents.get(statement)?.type === "Program" ? statement : void 0;
4292
4474
  }
4293
4475
  /**
4294
4476
  * Renames each tag of an alias to the component it names, where that name
@@ -4298,13 +4480,23 @@ var Inliner = class {
4298
4480
  renameAliasTags() {
4299
4481
  let renamed = false;
4300
4482
  for (const binding of this.context.scopes.root.bindings.values()) {
4301
- const target = this.aliasTarget(binding);
4483
+ const compound = this.compoundTarget(binding);
4484
+ const target = this.aliasTarget(binding) ?? compound?.root;
4302
4485
  if (!target) continue;
4303
4486
  for (const reference of binding.references) {
4304
4487
  const parent = this.context.parents.get(reference);
4305
- if (parent?.type !== "JSXOpeningElement" && parent?.type !== "JSXClosingElement" || parent.name !== reference) continue;
4306
- if (lookup(scopeAt(this.context.scopes, this.context.parents, reference), target.name) !== target) continue;
4307
- this.context.s.overwrite(reference.start, reference.end, target.name);
4488
+ let tag = reference;
4489
+ let renamedTo = target;
4490
+ if (parent?.type === "JSXMemberExpression" && parent.object === reference) {
4491
+ const part = compound?.parts.get(parent.property.name);
4492
+ if (!part) continue;
4493
+ tag = parent;
4494
+ renamedTo = part;
4495
+ }
4496
+ const element = this.context.parents.get(tag);
4497
+ if (element?.type !== "JSXOpeningElement" && element?.type !== "JSXClosingElement" || element.name !== tag) continue;
4498
+ if (lookup(scopeAt(this.context.scopes, this.context.parents, reference), renamedTo.name) !== renamedTo) continue;
4499
+ this.context.s.overwrite(tag.start, tag.end, renamedTo.name);
4308
4500
  renamed = true;
4309
4501
  }
4310
4502
  }
@@ -4521,6 +4713,11 @@ function hasChild(children, child) {
4521
4713
  for (const item of children) if (item === child) return true;
4522
4714
  return false;
4523
4715
  }
4716
+ /** The name a non-computed object key spells, like `Trigger` or `'Trigger'`. */
4717
+ function propertyKeyName(key) {
4718
+ if (key.type === "Identifier") return key.name;
4719
+ return key.type === "Literal" && typeof key.value === "string" ? key.value : void 0;
4720
+ }
4524
4721
  //#endregion
4525
4722
  //#region src/memo.ts
4526
4723
  /**
@@ -5494,6 +5691,58 @@ function expressionText(context, attribute) {
5494
5691
  }
5495
5692
  }
5496
5693
  //#endregion
5694
+ //#region src/terminate.ts
5695
+ const TERMINATED = /* @__PURE__ */ new Set([
5696
+ "BreakStatement",
5697
+ "ContinueStatement",
5698
+ "DebuggerStatement",
5699
+ "DoWhileStatement",
5700
+ "ExportAllDeclaration",
5701
+ "ExpressionStatement",
5702
+ "ImportDeclaration",
5703
+ "ReturnStatement",
5704
+ "ThrowStatement",
5705
+ "TSTypeAliasDeclaration",
5706
+ "VariableDeclaration"
5707
+ ]);
5708
+ const LOOP_HEADS = /* @__PURE__ */ new Set([
5709
+ "ForStatement",
5710
+ "ForInStatement",
5711
+ "ForOfStatement"
5712
+ ]);
5713
+ function isTerminated(node, context) {
5714
+ if (node.type === "VariableDeclaration") {
5715
+ const parent = context.parents.get(node);
5716
+ return !(parent && LOOP_HEADS.has(parent.type) && Reflect.get(parent, "body") !== node);
5717
+ }
5718
+ if (node.type === "ExportNamedDeclaration") return !node.declaration;
5719
+ if (node.type === "ExportDefaultDeclaration") {
5720
+ const { type } = node.declaration;
5721
+ return type !== "FunctionDeclaration" && type !== "ClassDeclaration";
5722
+ }
5723
+ return TERMINATED.has(node.type);
5724
+ }
5725
+ const TRIVIA = /(?:\s|\/\/[^\n\r\u2028\u2029]*|\/\*[\s\S]*?\*\/)*/y;
5726
+ /** Whether code other than the closing brace of a block follows `position`. */
5727
+ function hasCodeAfter(code, position) {
5728
+ TRIVIA.lastIndex = position;
5729
+ TRIVIA.exec(code);
5730
+ return TRIVIA.lastIndex < code.length && code[TRIVIA.lastIndex] !== "}";
5731
+ }
5732
+ function terminateStatements(context) {
5733
+ const { code, s } = context;
5734
+ let changed = false;
5735
+ const visit = (node) => {
5736
+ if (isTerminated(node, context) && code[node.end - 1] !== ";" && hasCodeAfter(code, node.end)) {
5737
+ s.appendLeft(node.end, ";");
5738
+ changed = true;
5739
+ }
5740
+ forEachChild(node, visit);
5741
+ };
5742
+ visit(context.program);
5743
+ return changed;
5744
+ }
5745
+ //#endregion
5497
5746
  //#region src/compile.ts
5498
5747
  const DEFAULT_BUILT_INS = [
5499
5748
  "For",
@@ -5585,6 +5834,12 @@ function compile(code, options = {}) {
5585
5834
  if (parsed?.code !== current) parsed = parseCode(current, filename);
5586
5835
  return parsed;
5587
5836
  };
5837
+ const terminated = runPass(parsedCurrent(), filename, resolved, sourceMap, terminateStatements, void 0);
5838
+ if (terminated) {
5839
+ current = terminated.code;
5840
+ if (terminated.map !== void 0) maps.push(terminated.map);
5841
+ }
5842
+ const start = current;
5588
5843
  const maxPasses = options.maxPasses ?? 10;
5589
5844
  let skipped;
5590
5845
  for (let round = 0; round < maxPasses; round += 1) {
@@ -5606,7 +5861,7 @@ function compile(code, options = {}) {
5606
5861
  current = result.code;
5607
5862
  if (result.map !== void 0) maps.push(result.map);
5608
5863
  }
5609
- if (current !== code) {
5864
+ if (current !== start) {
5610
5865
  const result = runPass(parsedCurrent(), filename, resolved, sourceMap, repairNesting, void 0);
5611
5866
  if (result) {
5612
5867
  current = result.code;
@@ -5614,6 +5869,11 @@ function compile(code, options = {}) {
5614
5869
  }
5615
5870
  }
5616
5871
  const report = skipped ? { skipped } : {};
5872
+ if (current === start) return {
5873
+ code,
5874
+ map: null,
5875
+ ...report
5876
+ };
5617
5877
  if (maps.length === 0) return {
5618
5878
  code: current,
5619
5879
  map: null,
@@ -5640,6 +5900,6 @@ function readModuleConstants(code, options = {}) {
5640
5900
  };
5641
5901
  }
5642
5902
  //#endregion
5643
- export { lookup as a, forEachChild as c, unwrap as d, analyzeScopes as i, isIntrinsicTag as l, readModuleConstants as n, scopeAt as o, CONTEXT_SAFE_PRIMITIVES as r, collectParents as s, compile as t, parse$1 as u };
5903
+ export { analyzeScopes as a, collectParents as c, parse$1 as d, unwrap as f, runtimeImportSources as i, forEachChild as l, readModuleConstants as n, lookup as o, CONTEXT_SAFE_PRIMITIVES as r, scopeAt as s, compile as t, isIntrinsicTag as u };
5644
5904
 
5645
- //# sourceMappingURL=compile-BuPR3pVT.mjs.map
5905
+ //# sourceMappingURL=compile-DptOANJi.mjs.map