@danielx/civet 0.5.53 → 0.5.54

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/dist/browser.js CHANGED
@@ -429,6 +429,7 @@ ${input.slice(result.pos)}
429
429
  Program,
430
430
  TopLevelStatement,
431
431
  ExtendedExpression,
432
+ SingleLineExtendedExpression,
432
433
  NonPipelineExtendedExpression,
433
434
  NonAssignmentExtendedExpression,
434
435
  ExpressionizedStatement,
@@ -1271,6 +1272,30 @@ ${input.slice(result.pos)}
1271
1272
  return result;
1272
1273
  }
1273
1274
  }
1275
+ var SingleLineExtendedExpression$0 = NonAssignmentExtendedExpression;
1276
+ var SingleLineExtendedExpression$1 = SingleLineAssignmentExpression;
1277
+ function SingleLineExtendedExpression(state) {
1278
+ let eventData;
1279
+ if (state.events) {
1280
+ const result = state.events.enter?.("SingleLineExtendedExpression", state);
1281
+ if (result) {
1282
+ if (result.cache)
1283
+ return result.cache;
1284
+ eventData = result.data;
1285
+ }
1286
+ }
1287
+ if (state.tokenize) {
1288
+ const result = $TOKEN("SingleLineExtendedExpression", state, SingleLineExtendedExpression$0(state) || SingleLineExtendedExpression$1(state));
1289
+ if (state.events)
1290
+ state.events.exit?.("SingleLineExtendedExpression", state, result, eventData);
1291
+ return result;
1292
+ } else {
1293
+ const result = SingleLineExtendedExpression$0(state) || SingleLineExtendedExpression$1(state);
1294
+ if (state.events)
1295
+ state.events.exit?.("SingleLineExtendedExpression", state, result, eventData);
1296
+ return result;
1297
+ }
1298
+ }
1274
1299
  var NonPipelineExtendedExpression$0 = NonAssignmentExtendedExpression;
1275
1300
  var NonPipelineExtendedExpression$1 = NonPipelineAssignmentExpression;
1276
1301
  function NonPipelineExtendedExpression(state) {
@@ -1968,20 +1993,7 @@ ${input.slice(result.pos)}
1968
1993
  }
1969
1994
  }
1970
1995
  var AssignmentExpression$0 = PipelineExpression;
1971
- var AssignmentExpression$1 = $TS($S($Q(TrailingComment), AssignmentExpressionTail), function($skip, $loc, $0, $1, $2) {
1972
- var ws = $1;
1973
- var tail = $2;
1974
- if (ws.length) {
1975
- if (tail.children && tail.type !== "IterationExpression") {
1976
- return {
1977
- ...tail,
1978
- children: [...ws, ...tail.children]
1979
- };
1980
- }
1981
- return $0;
1982
- }
1983
- return tail;
1984
- });
1996
+ var AssignmentExpression$1 = SingleLineAssignmentExpression;
1985
1997
  var AssignmentExpression$2 = $S(__, AssignmentExpressionTail);
1986
1998
  function AssignmentExpression(state) {
1987
1999
  let eventData;
@@ -4909,7 +4921,7 @@ ${input.slice(result.pos)}
4909
4921
  return result;
4910
4922
  }
4911
4923
  }
4912
- var SingleLineStatements$0 = $TS($S($Q($S($Q(_), Statement, SemicolonDelimiter)), $E($S($Q(_), Statement, $E(SemicolonDelimiter)))), function($skip, $loc, $0, $1, $2) {
4924
+ var SingleLineStatements$0 = $TS($S($Q($S($S($E(_), $N(EOS)), Statement, SemicolonDelimiter)), $E($S($S($E(_), $N(EOS)), Statement, $E(SemicolonDelimiter)))), function($skip, $loc, $0, $1, $2) {
4913
4925
  var stmts = $1;
4914
4926
  var last = $2;
4915
4927
  const children = [...stmts];
@@ -9385,7 +9397,12 @@ ${input.slice(result.pos)}
9385
9397
  return result;
9386
9398
  }
9387
9399
  }
9388
- var ExportVarDec$0 = $S(InsertVar, VariableDeclarationList);
9400
+ var ExportVarDec$0 = $TS($S(InsertVar, VariableDeclarationList), function($skip, $loc, $0, $1, $2) {
9401
+ return {
9402
+ ...$2,
9403
+ children: [$1, ...$2.children]
9404
+ };
9405
+ });
9389
9406
  function ExportVarDec(state) {
9390
9407
  let eventData;
9391
9408
  if (state.events) {
@@ -18129,9 +18146,6 @@ ${input.slice(result.pos)}
18129
18146
  scopes.pop();
18130
18147
  }
18131
18148
  function createLetDecs(statements, scopes) {
18132
- function hasDec(name) {
18133
- return scopes.some((s) => s.has(name));
18134
- }
18135
18149
  function findVarDecs(statements2, decs) {
18136
18150
  const declarationNames = gatherRecursive(
18137
18151
  statements2,
@@ -18139,52 +18153,68 @@ ${input.slice(result.pos)}
18139
18153
  ).filter((node) => node.type === "Declaration").flatMap((node) => node.names);
18140
18154
  return new Set(declarationNames);
18141
18155
  }
18142
- function insertBeforeAssignment(assignment, content) {
18143
- if (assignment.children && assignment.children.length) {
18144
- let indent = assignment.children[0][0][0];
18145
- if (Array.isArray(indent))
18146
- indent = indent[indent.length - 1];
18147
- assignment.children.unshift([indent, ...content]);
18148
- }
18156
+ let declaredIdentifiers = findVarDecs(statements);
18157
+ function hasDec(name) {
18158
+ return declaredIdentifiers.has(name) || scopes.some((s) => s.has(name));
18159
+ }
18160
+ function gatherBlockOrOther(statement) {
18161
+ return gatherNodes(statement, (s) => s.type === "BlockStatement" || s.type === "AssignmentExpression" || s.type === "Declaration").flatMap((node) => {
18162
+ if (node.type == "BlockStatement")
18163
+ return node.bare ? gatherBlockOrOther(node.expressions) : node;
18164
+ else if (node.children && node.children.length)
18165
+ return [...gatherBlockOrOther(node.children), node];
18166
+ else
18167
+ return [];
18168
+ });
18149
18169
  }
18150
18170
  let currentScope = /* @__PURE__ */ new Set();
18151
18171
  scopes.push(currentScope);
18152
18172
  const fnNodes = gatherNodes(statements, (s) => s.type === "FunctionExpression");
18153
18173
  const forNodes = gatherNodes(statements, (s) => s.type === "ForStatement");
18154
- const nodes = gatherNodes(statements, (s) => s.type === "BlockStatement" || s.type === "AssignmentExpression" || s.type === "Declaration");
18155
- let declaredIdentifiers = findVarDecs(statements);
18156
- for (const node of nodes) {
18157
- if (node.type == "AssignmentExpression") {
18158
- let undeclaredIdentifiers = node.names.filter((name) => !(hasDec(name) || declaredIdentifiers.has(name)));
18159
- if (node.children.length)
18160
- createLetDecs(node.children, scopes);
18161
- undeclaredIdentifiers.forEach((name) => currentScope.add(name));
18162
- if (node.names.length === undeclaredIdentifiers.length) {
18163
- insertBeforeAssignment(node, ["let "]);
18164
- } else if (undeclaredIdentifiers.length > 0) {
18165
- insertBeforeAssignment(node, ["let ", undeclaredIdentifiers.join(", "), "\n"]);
18174
+ let targetStatements = [];
18175
+ for (const statement of statements) {
18176
+ const nodes = gatherBlockOrOther(statement);
18177
+ let undeclaredIdentifiers = [];
18178
+ for (const node of nodes) {
18179
+ if (node.type == "BlockStatement") {
18180
+ let block = node;
18181
+ let fnNode = fnNodes.find((fnNode2) => fnNode2.block === block);
18182
+ let forNode = forNodes.find((forNode2) => forNode2.block === block);
18183
+ if (fnNode != null) {
18184
+ scopes.push(new Set(fnNode.parameters.names));
18185
+ createLetDecs(block.expressions, scopes);
18186
+ scopes.pop();
18187
+ } else if (forNode != null) {
18188
+ scopes.push(new Set(forNode.declaration.names));
18189
+ createLetDecs(block.expressions, scopes);
18190
+ scopes.pop();
18191
+ } else
18192
+ createLetDecs(block.expressions, scopes);
18193
+ continue;
18194
+ }
18195
+ if (node.names == null)
18196
+ continue;
18197
+ let names = node.names.filter((name) => !hasDec(name));
18198
+ if (node.type == "AssignmentExpression")
18199
+ undeclaredIdentifiers.push(...names);
18200
+ names.forEach((name) => currentScope.add(name));
18201
+ }
18202
+ if (undeclaredIdentifiers.length > 0) {
18203
+ let indent = statement[0];
18204
+ let firstIdentifier = gatherNodes(statement[1], (node) => node.type == "Identifier")[0];
18205
+ if (undeclaredIdentifiers.length == 1 && statement[1].type == "AssignmentExpression" && statement[1].names.length == 1 && statement[1].names[0] == undeclaredIdentifiers[0] && firstIdentifier && firstIdentifier.names == undeclaredIdentifiers[0] && gatherNodes(statement[1], (node) => node.type === "ObjectBindingPattern").length == 0)
18206
+ statement[1].children.unshift(["let "]);
18207
+ else {
18208
+ let tail = "\n";
18209
+ if (gatherNodes(indent, (node) => node.token && node.token.endsWith("\n")).length > 0)
18210
+ tail = void 0;
18211
+ targetStatements.push([indent, "let ", undeclaredIdentifiers.join(", "), tail]);
18166
18212
  }
18167
- } else if (node.type == "Declaration") {
18168
- if (node.children && node.children.length)
18169
- createLetDecs(node.children, scopes);
18170
- node.names.forEach((name) => currentScope.add(name));
18171
- } else {
18172
- let block = node;
18173
- let fnNode = fnNodes.find((fnNode2) => fnNode2.block === block);
18174
- let forNode = forNodes.find((forNode2) => forNode2.block === block);
18175
- if (fnNode != null) {
18176
- scopes.push(new Set(fnNode.parameters.names));
18177
- createLetDecs(block.expressions, scopes);
18178
- scopes.pop();
18179
- } else if (forNode != null) {
18180
- scopes.push(new Set(forNode.declaration.names));
18181
- createLetDecs(block.expressions, scopes);
18182
- scopes.pop();
18183
- } else
18184
- createLetDecs(block.expressions, scopes);
18185
18213
  }
18214
+ targetStatements.push(statement);
18186
18215
  }
18187
18216
  scopes.pop();
18217
+ statements.splice(0, statements.length, targetStatements);
18188
18218
  }
18189
18219
  function gatherBindingCode(statements, opts) {
18190
18220
  const thisAssignments = [];
@@ -18901,7 +18931,7 @@ ${input.slice(result.pos)}
18901
18931
  ({ parse } = import_parser.default);
18902
18932
  ({ SourceMap: SourceMap2, base64Encode: base64Encode2 } = util_exports);
18903
18933
  defaultOptions = {};
18904
- uncacheable = /* @__PURE__ */ new Set(["ActualAssignment", "ApplicationStart", "Arguments", "ArgumentsWithTrailingMemberExpressions", "ArrowFunction", "ArrowFunctionTail", "AssignmentExpression", "AssignmentExpressionTail", "BinaryOpExpression", "BinaryOpRHS", "BracedBlock", "BracedObjectLiteralContent", "BracedOrEmptyBlock", "CallExpression", "CallExpressionRest", "CoffeeCommentEnabled", "CommaDelimiter", "ConditionalExpression", "Declaration", "Debugger", "ElseClause", "Expression", "ExpressionStatement", "ExpressionWithIndentedApplicationSuppressed", "ExtendedExpression", "FatArrowBody", "FunctionDeclaration", "FunctionExpression", "HoistableDeclaration", "ImplicitArguments", "ImplicitInlineObjectPropertyDelimiter", "ImplicitNestedBlock", "IndentedApplicationAllowed", "IndentedFurther", "IndentedJSXChildExpression", "InlineObjectLiteral", "InsertIndent", "JSXChild", "JSXChildren", "JSXElement", "JSXFragment", "JSXImplicitFragment", "JSXMixedChildren", "JSXNested", "JSXNestedChildren", "JSXOptionalClosingElement", "JSXOptionalClosingFragment", "JSXTag", "LeftHandSideExpression", "MemberExpression", "MemberExpressionRest", "Nested", "NestedBindingElement", "NestedBindingElements", "NestedBlockExpression", "NestedBlockExpression", "NestedBlockStatement", "NestedBlockStatements", "NestedElement", "NestedElementList", "NestedImplicitObjectLiteral", "NestedImplicitPropertyDefinition", "NestedImplicitPropertyDefinitions", "NestedInterfaceProperty", "NestedJSXChildExpression", "NestedObject", "NestedPropertyDefinitions", "NonSuppressedTrailingMemberExpressions", "ObjectLiteral", "PopIndent", "PrimaryExpression", "PushIndent", "PushJSXOpeningElement", "PushJSXOpeningFragment", "Samedent", "ShortCircuitExpression", "SingleLineComment", "SingleLineStatements", "SnugNamedProperty", "Statement", "StatementListItem", "SuppressIndentedApplication", "SuppressTrailingMemberProperty", "ThinArrowFunction", "TrackIndented", "TrailingMemberExpressions", "TrailingMemberPropertyAllowed", "TypedJSXElement", "TypedJSXFragment", "UnaryExpression", "UpdateExpression"]);
18934
+ uncacheable = /* @__PURE__ */ new Set(["ActualAssignment", "ApplicationStart", "Arguments", "ArgumentsWithTrailingMemberExpressions", "ArrowFunction", "ArrowFunctionTail", "AssignmentExpression", "AssignmentExpressionTail", "BinaryOpExpression", "BinaryOpRHS", "BracedBlock", "BracedObjectLiteralContent", "BracedOrEmptyBlock", "CallExpression", "CallExpressionRest", "CoffeeCommentEnabled", "CommaDelimiter", "ConditionalExpression", "Declaration", "Debugger", "ElseClause", "Expression", "ExpressionStatement", "ExpressionWithIndentedApplicationSuppressed", "ExtendedExpression", "FatArrowBody", "FunctionDeclaration", "FunctionExpression", "HoistableDeclaration", "ImplicitArguments", "ImplicitInlineObjectPropertyDelimiter", "ImplicitNestedBlock", "IndentedApplicationAllowed", "IndentedFurther", "IndentedJSXChildExpression", "InlineObjectLiteral", "InsertIndent", "JSXChild", "JSXChildren", "JSXElement", "JSXFragment", "JSXImplicitFragment", "JSXMixedChildren", "JSXNested", "JSXNestedChildren", "JSXOptionalClosingElement", "JSXOptionalClosingFragment", "JSXTag", "LeftHandSideExpression", "MemberExpression", "MemberExpressionRest", "Nested", "NestedBindingElement", "NestedBindingElements", "NestedBlockExpression", "NestedBlockExpression", "NestedBlockStatement", "NestedBlockStatements", "NestedElement", "NestedElementList", "NestedImplicitObjectLiteral", "NestedImplicitPropertyDefinition", "NestedImplicitPropertyDefinitions", "NestedInterfaceProperty", "NestedJSXChildExpression", "NestedObject", "NestedPropertyDefinitions", "NonSuppressedTrailingMemberExpressions", "ObjectLiteral", "PopIndent", "PrimaryExpression", "PushIndent", "PushJSXOpeningElement", "PushJSXOpeningFragment", "Samedent", "ShortCircuitExpression", "SingleLineAssignmentExpression", "SingleLineComment", "SingleLineStatements", "SnugNamedProperty", "Statement", "StatementListItem", "SuppressIndentedApplication", "SuppressTrailingMemberProperty", "ThinArrowFunction", "TrackIndented", "TrailingMemberExpressions", "TrailingMemberPropertyAllowed", "TypedJSXElement", "TypedJSXFragment", "UnaryExpression", "UpdateExpression"]);
18905
18935
  var compile = function(src, options = defaultOptions) {
18906
18936
  var ast, code, events, filename, sm, srcMapJSON;
18907
18937
  filename = options.filename || "unknown";
package/dist/main.js CHANGED
@@ -428,6 +428,7 @@ ${input.slice(result.pos)}
428
428
  Program,
429
429
  TopLevelStatement,
430
430
  ExtendedExpression,
431
+ SingleLineExtendedExpression,
431
432
  NonPipelineExtendedExpression,
432
433
  NonAssignmentExtendedExpression,
433
434
  ExpressionizedStatement,
@@ -1270,6 +1271,30 @@ ${input.slice(result.pos)}
1270
1271
  return result;
1271
1272
  }
1272
1273
  }
1274
+ var SingleLineExtendedExpression$0 = NonAssignmentExtendedExpression;
1275
+ var SingleLineExtendedExpression$1 = SingleLineAssignmentExpression;
1276
+ function SingleLineExtendedExpression(state) {
1277
+ let eventData;
1278
+ if (state.events) {
1279
+ const result = state.events.enter?.("SingleLineExtendedExpression", state);
1280
+ if (result) {
1281
+ if (result.cache)
1282
+ return result.cache;
1283
+ eventData = result.data;
1284
+ }
1285
+ }
1286
+ if (state.tokenize) {
1287
+ const result = $TOKEN("SingleLineExtendedExpression", state, SingleLineExtendedExpression$0(state) || SingleLineExtendedExpression$1(state));
1288
+ if (state.events)
1289
+ state.events.exit?.("SingleLineExtendedExpression", state, result, eventData);
1290
+ return result;
1291
+ } else {
1292
+ const result = SingleLineExtendedExpression$0(state) || SingleLineExtendedExpression$1(state);
1293
+ if (state.events)
1294
+ state.events.exit?.("SingleLineExtendedExpression", state, result, eventData);
1295
+ return result;
1296
+ }
1297
+ }
1273
1298
  var NonPipelineExtendedExpression$0 = NonAssignmentExtendedExpression;
1274
1299
  var NonPipelineExtendedExpression$1 = NonPipelineAssignmentExpression;
1275
1300
  function NonPipelineExtendedExpression(state) {
@@ -1967,20 +1992,7 @@ ${input.slice(result.pos)}
1967
1992
  }
1968
1993
  }
1969
1994
  var AssignmentExpression$0 = PipelineExpression;
1970
- var AssignmentExpression$1 = $TS($S($Q(TrailingComment), AssignmentExpressionTail), function($skip, $loc, $0, $1, $2) {
1971
- var ws = $1;
1972
- var tail = $2;
1973
- if (ws.length) {
1974
- if (tail.children && tail.type !== "IterationExpression") {
1975
- return {
1976
- ...tail,
1977
- children: [...ws, ...tail.children]
1978
- };
1979
- }
1980
- return $0;
1981
- }
1982
- return tail;
1983
- });
1995
+ var AssignmentExpression$1 = SingleLineAssignmentExpression;
1984
1996
  var AssignmentExpression$2 = $S(__, AssignmentExpressionTail);
1985
1997
  function AssignmentExpression(state) {
1986
1998
  let eventData;
@@ -4908,7 +4920,7 @@ ${input.slice(result.pos)}
4908
4920
  return result;
4909
4921
  }
4910
4922
  }
4911
- var SingleLineStatements$0 = $TS($S($Q($S($Q(_), Statement, SemicolonDelimiter)), $E($S($Q(_), Statement, $E(SemicolonDelimiter)))), function($skip, $loc, $0, $1, $2) {
4923
+ var SingleLineStatements$0 = $TS($S($Q($S($S($E(_), $N(EOS)), Statement, SemicolonDelimiter)), $E($S($S($E(_), $N(EOS)), Statement, $E(SemicolonDelimiter)))), function($skip, $loc, $0, $1, $2) {
4912
4924
  var stmts = $1;
4913
4925
  var last = $2;
4914
4926
  const children = [...stmts];
@@ -9384,7 +9396,12 @@ ${input.slice(result.pos)}
9384
9396
  return result;
9385
9397
  }
9386
9398
  }
9387
- var ExportVarDec$0 = $S(InsertVar, VariableDeclarationList);
9399
+ var ExportVarDec$0 = $TS($S(InsertVar, VariableDeclarationList), function($skip, $loc, $0, $1, $2) {
9400
+ return {
9401
+ ...$2,
9402
+ children: [$1, ...$2.children]
9403
+ };
9404
+ });
9388
9405
  function ExportVarDec(state) {
9389
9406
  let eventData;
9390
9407
  if (state.events) {
@@ -18128,9 +18145,6 @@ ${input.slice(result.pos)}
18128
18145
  scopes.pop();
18129
18146
  }
18130
18147
  function createLetDecs(statements, scopes) {
18131
- function hasDec(name) {
18132
- return scopes.some((s) => s.has(name));
18133
- }
18134
18148
  function findVarDecs(statements2, decs) {
18135
18149
  const declarationNames = gatherRecursive(
18136
18150
  statements2,
@@ -18138,52 +18152,68 @@ ${input.slice(result.pos)}
18138
18152
  ).filter((node) => node.type === "Declaration").flatMap((node) => node.names);
18139
18153
  return new Set(declarationNames);
18140
18154
  }
18141
- function insertBeforeAssignment(assignment, content) {
18142
- if (assignment.children && assignment.children.length) {
18143
- let indent = assignment.children[0][0][0];
18144
- if (Array.isArray(indent))
18145
- indent = indent[indent.length - 1];
18146
- assignment.children.unshift([indent, ...content]);
18147
- }
18155
+ let declaredIdentifiers = findVarDecs(statements);
18156
+ function hasDec(name) {
18157
+ return declaredIdentifiers.has(name) || scopes.some((s) => s.has(name));
18158
+ }
18159
+ function gatherBlockOrOther(statement) {
18160
+ return gatherNodes(statement, (s) => s.type === "BlockStatement" || s.type === "AssignmentExpression" || s.type === "Declaration").flatMap((node) => {
18161
+ if (node.type == "BlockStatement")
18162
+ return node.bare ? gatherBlockOrOther(node.expressions) : node;
18163
+ else if (node.children && node.children.length)
18164
+ return [...gatherBlockOrOther(node.children), node];
18165
+ else
18166
+ return [];
18167
+ });
18148
18168
  }
18149
18169
  let currentScope = /* @__PURE__ */ new Set();
18150
18170
  scopes.push(currentScope);
18151
18171
  const fnNodes = gatherNodes(statements, (s) => s.type === "FunctionExpression");
18152
18172
  const forNodes = gatherNodes(statements, (s) => s.type === "ForStatement");
18153
- const nodes = gatherNodes(statements, (s) => s.type === "BlockStatement" || s.type === "AssignmentExpression" || s.type === "Declaration");
18154
- let declaredIdentifiers = findVarDecs(statements);
18155
- for (const node of nodes) {
18156
- if (node.type == "AssignmentExpression") {
18157
- let undeclaredIdentifiers = node.names.filter((name) => !(hasDec(name) || declaredIdentifiers.has(name)));
18158
- if (node.children.length)
18159
- createLetDecs(node.children, scopes);
18160
- undeclaredIdentifiers.forEach((name) => currentScope.add(name));
18161
- if (node.names.length === undeclaredIdentifiers.length) {
18162
- insertBeforeAssignment(node, ["let "]);
18163
- } else if (undeclaredIdentifiers.length > 0) {
18164
- insertBeforeAssignment(node, ["let ", undeclaredIdentifiers.join(", "), "\n"]);
18173
+ let targetStatements = [];
18174
+ for (const statement of statements) {
18175
+ const nodes = gatherBlockOrOther(statement);
18176
+ let undeclaredIdentifiers = [];
18177
+ for (const node of nodes) {
18178
+ if (node.type == "BlockStatement") {
18179
+ let block = node;
18180
+ let fnNode = fnNodes.find((fnNode2) => fnNode2.block === block);
18181
+ let forNode = forNodes.find((forNode2) => forNode2.block === block);
18182
+ if (fnNode != null) {
18183
+ scopes.push(new Set(fnNode.parameters.names));
18184
+ createLetDecs(block.expressions, scopes);
18185
+ scopes.pop();
18186
+ } else if (forNode != null) {
18187
+ scopes.push(new Set(forNode.declaration.names));
18188
+ createLetDecs(block.expressions, scopes);
18189
+ scopes.pop();
18190
+ } else
18191
+ createLetDecs(block.expressions, scopes);
18192
+ continue;
18193
+ }
18194
+ if (node.names == null)
18195
+ continue;
18196
+ let names = node.names.filter((name) => !hasDec(name));
18197
+ if (node.type == "AssignmentExpression")
18198
+ undeclaredIdentifiers.push(...names);
18199
+ names.forEach((name) => currentScope.add(name));
18200
+ }
18201
+ if (undeclaredIdentifiers.length > 0) {
18202
+ let indent = statement[0];
18203
+ let firstIdentifier = gatherNodes(statement[1], (node) => node.type == "Identifier")[0];
18204
+ if (undeclaredIdentifiers.length == 1 && statement[1].type == "AssignmentExpression" && statement[1].names.length == 1 && statement[1].names[0] == undeclaredIdentifiers[0] && firstIdentifier && firstIdentifier.names == undeclaredIdentifiers[0] && gatherNodes(statement[1], (node) => node.type === "ObjectBindingPattern").length == 0)
18205
+ statement[1].children.unshift(["let "]);
18206
+ else {
18207
+ let tail = "\n";
18208
+ if (gatherNodes(indent, (node) => node.token && node.token.endsWith("\n")).length > 0)
18209
+ tail = void 0;
18210
+ targetStatements.push([indent, "let ", undeclaredIdentifiers.join(", "), tail]);
18165
18211
  }
18166
- } else if (node.type == "Declaration") {
18167
- if (node.children && node.children.length)
18168
- createLetDecs(node.children, scopes);
18169
- node.names.forEach((name) => currentScope.add(name));
18170
- } else {
18171
- let block = node;
18172
- let fnNode = fnNodes.find((fnNode2) => fnNode2.block === block);
18173
- let forNode = forNodes.find((forNode2) => forNode2.block === block);
18174
- if (fnNode != null) {
18175
- scopes.push(new Set(fnNode.parameters.names));
18176
- createLetDecs(block.expressions, scopes);
18177
- scopes.pop();
18178
- } else if (forNode != null) {
18179
- scopes.push(new Set(forNode.declaration.names));
18180
- createLetDecs(block.expressions, scopes);
18181
- scopes.pop();
18182
- } else
18183
- createLetDecs(block.expressions, scopes);
18184
18212
  }
18213
+ targetStatements.push(statement);
18185
18214
  }
18186
18215
  scopes.pop();
18216
+ statements.splice(0, statements.length, targetStatements);
18187
18217
  }
18188
18218
  function gatherBindingCode(statements, opts) {
18189
18219
  const thisAssignments = [];
@@ -18901,7 +18931,7 @@ var uncacheable;
18901
18931
  ({ parse } = import_parser.default);
18902
18932
  ({ SourceMap: SourceMap2, base64Encode: base64Encode2 } = util_exports);
18903
18933
  defaultOptions = {};
18904
- uncacheable = /* @__PURE__ */ new Set(["ActualAssignment", "ApplicationStart", "Arguments", "ArgumentsWithTrailingMemberExpressions", "ArrowFunction", "ArrowFunctionTail", "AssignmentExpression", "AssignmentExpressionTail", "BinaryOpExpression", "BinaryOpRHS", "BracedBlock", "BracedObjectLiteralContent", "BracedOrEmptyBlock", "CallExpression", "CallExpressionRest", "CoffeeCommentEnabled", "CommaDelimiter", "ConditionalExpression", "Declaration", "Debugger", "ElseClause", "Expression", "ExpressionStatement", "ExpressionWithIndentedApplicationSuppressed", "ExtendedExpression", "FatArrowBody", "FunctionDeclaration", "FunctionExpression", "HoistableDeclaration", "ImplicitArguments", "ImplicitInlineObjectPropertyDelimiter", "ImplicitNestedBlock", "IndentedApplicationAllowed", "IndentedFurther", "IndentedJSXChildExpression", "InlineObjectLiteral", "InsertIndent", "JSXChild", "JSXChildren", "JSXElement", "JSXFragment", "JSXImplicitFragment", "JSXMixedChildren", "JSXNested", "JSXNestedChildren", "JSXOptionalClosingElement", "JSXOptionalClosingFragment", "JSXTag", "LeftHandSideExpression", "MemberExpression", "MemberExpressionRest", "Nested", "NestedBindingElement", "NestedBindingElements", "NestedBlockExpression", "NestedBlockExpression", "NestedBlockStatement", "NestedBlockStatements", "NestedElement", "NestedElementList", "NestedImplicitObjectLiteral", "NestedImplicitPropertyDefinition", "NestedImplicitPropertyDefinitions", "NestedInterfaceProperty", "NestedJSXChildExpression", "NestedObject", "NestedPropertyDefinitions", "NonSuppressedTrailingMemberExpressions", "ObjectLiteral", "PopIndent", "PrimaryExpression", "PushIndent", "PushJSXOpeningElement", "PushJSXOpeningFragment", "Samedent", "ShortCircuitExpression", "SingleLineComment", "SingleLineStatements", "SnugNamedProperty", "Statement", "StatementListItem", "SuppressIndentedApplication", "SuppressTrailingMemberProperty", "ThinArrowFunction", "TrackIndented", "TrailingMemberExpressions", "TrailingMemberPropertyAllowed", "TypedJSXElement", "TypedJSXFragment", "UnaryExpression", "UpdateExpression"]);
18934
+ uncacheable = /* @__PURE__ */ new Set(["ActualAssignment", "ApplicationStart", "Arguments", "ArgumentsWithTrailingMemberExpressions", "ArrowFunction", "ArrowFunctionTail", "AssignmentExpression", "AssignmentExpressionTail", "BinaryOpExpression", "BinaryOpRHS", "BracedBlock", "BracedObjectLiteralContent", "BracedOrEmptyBlock", "CallExpression", "CallExpressionRest", "CoffeeCommentEnabled", "CommaDelimiter", "ConditionalExpression", "Declaration", "Debugger", "ElseClause", "Expression", "ExpressionStatement", "ExpressionWithIndentedApplicationSuppressed", "ExtendedExpression", "FatArrowBody", "FunctionDeclaration", "FunctionExpression", "HoistableDeclaration", "ImplicitArguments", "ImplicitInlineObjectPropertyDelimiter", "ImplicitNestedBlock", "IndentedApplicationAllowed", "IndentedFurther", "IndentedJSXChildExpression", "InlineObjectLiteral", "InsertIndent", "JSXChild", "JSXChildren", "JSXElement", "JSXFragment", "JSXImplicitFragment", "JSXMixedChildren", "JSXNested", "JSXNestedChildren", "JSXOptionalClosingElement", "JSXOptionalClosingFragment", "JSXTag", "LeftHandSideExpression", "MemberExpression", "MemberExpressionRest", "Nested", "NestedBindingElement", "NestedBindingElements", "NestedBlockExpression", "NestedBlockExpression", "NestedBlockStatement", "NestedBlockStatements", "NestedElement", "NestedElementList", "NestedImplicitObjectLiteral", "NestedImplicitPropertyDefinition", "NestedImplicitPropertyDefinitions", "NestedInterfaceProperty", "NestedJSXChildExpression", "NestedObject", "NestedPropertyDefinitions", "NonSuppressedTrailingMemberExpressions", "ObjectLiteral", "PopIndent", "PrimaryExpression", "PushIndent", "PushJSXOpeningElement", "PushJSXOpeningFragment", "Samedent", "ShortCircuitExpression", "SingleLineAssignmentExpression", "SingleLineComment", "SingleLineStatements", "SnugNamedProperty", "Statement", "StatementListItem", "SuppressIndentedApplication", "SuppressTrailingMemberProperty", "ThinArrowFunction", "TrackIndented", "TrailingMemberExpressions", "TrailingMemberPropertyAllowed", "TypedJSXElement", "TypedJSXFragment", "UnaryExpression", "UpdateExpression"]);
18905
18935
  var compile = function(src, options = defaultOptions) {
18906
18936
  var ast, code, events, filename, sm, srcMapJSON;
18907
18937
  filename = options.filename || "unknown";
package/dist/main.mjs CHANGED
@@ -426,6 +426,7 @@ ${input.slice(result.pos)}
426
426
  Program,
427
427
  TopLevelStatement,
428
428
  ExtendedExpression,
429
+ SingleLineExtendedExpression,
429
430
  NonPipelineExtendedExpression,
430
431
  NonAssignmentExtendedExpression,
431
432
  ExpressionizedStatement,
@@ -1268,6 +1269,30 @@ ${input.slice(result.pos)}
1268
1269
  return result;
1269
1270
  }
1270
1271
  }
1272
+ var SingleLineExtendedExpression$0 = NonAssignmentExtendedExpression;
1273
+ var SingleLineExtendedExpression$1 = SingleLineAssignmentExpression;
1274
+ function SingleLineExtendedExpression(state) {
1275
+ let eventData;
1276
+ if (state.events) {
1277
+ const result = state.events.enter?.("SingleLineExtendedExpression", state);
1278
+ if (result) {
1279
+ if (result.cache)
1280
+ return result.cache;
1281
+ eventData = result.data;
1282
+ }
1283
+ }
1284
+ if (state.tokenize) {
1285
+ const result = $TOKEN("SingleLineExtendedExpression", state, SingleLineExtendedExpression$0(state) || SingleLineExtendedExpression$1(state));
1286
+ if (state.events)
1287
+ state.events.exit?.("SingleLineExtendedExpression", state, result, eventData);
1288
+ return result;
1289
+ } else {
1290
+ const result = SingleLineExtendedExpression$0(state) || SingleLineExtendedExpression$1(state);
1291
+ if (state.events)
1292
+ state.events.exit?.("SingleLineExtendedExpression", state, result, eventData);
1293
+ return result;
1294
+ }
1295
+ }
1271
1296
  var NonPipelineExtendedExpression$0 = NonAssignmentExtendedExpression;
1272
1297
  var NonPipelineExtendedExpression$1 = NonPipelineAssignmentExpression;
1273
1298
  function NonPipelineExtendedExpression(state) {
@@ -1965,20 +1990,7 @@ ${input.slice(result.pos)}
1965
1990
  }
1966
1991
  }
1967
1992
  var AssignmentExpression$0 = PipelineExpression;
1968
- var AssignmentExpression$1 = $TS($S($Q(TrailingComment), AssignmentExpressionTail), function($skip, $loc, $0, $1, $2) {
1969
- var ws = $1;
1970
- var tail = $2;
1971
- if (ws.length) {
1972
- if (tail.children && tail.type !== "IterationExpression") {
1973
- return {
1974
- ...tail,
1975
- children: [...ws, ...tail.children]
1976
- };
1977
- }
1978
- return $0;
1979
- }
1980
- return tail;
1981
- });
1993
+ var AssignmentExpression$1 = SingleLineAssignmentExpression;
1982
1994
  var AssignmentExpression$2 = $S(__, AssignmentExpressionTail);
1983
1995
  function AssignmentExpression(state) {
1984
1996
  let eventData;
@@ -4906,7 +4918,7 @@ ${input.slice(result.pos)}
4906
4918
  return result;
4907
4919
  }
4908
4920
  }
4909
- var SingleLineStatements$0 = $TS($S($Q($S($Q(_), Statement, SemicolonDelimiter)), $E($S($Q(_), Statement, $E(SemicolonDelimiter)))), function($skip, $loc, $0, $1, $2) {
4921
+ var SingleLineStatements$0 = $TS($S($Q($S($S($E(_), $N(EOS)), Statement, SemicolonDelimiter)), $E($S($S($E(_), $N(EOS)), Statement, $E(SemicolonDelimiter)))), function($skip, $loc, $0, $1, $2) {
4910
4922
  var stmts = $1;
4911
4923
  var last = $2;
4912
4924
  const children = [...stmts];
@@ -9382,7 +9394,12 @@ ${input.slice(result.pos)}
9382
9394
  return result;
9383
9395
  }
9384
9396
  }
9385
- var ExportVarDec$0 = $S(InsertVar, VariableDeclarationList);
9397
+ var ExportVarDec$0 = $TS($S(InsertVar, VariableDeclarationList), function($skip, $loc, $0, $1, $2) {
9398
+ return {
9399
+ ...$2,
9400
+ children: [$1, ...$2.children]
9401
+ };
9402
+ });
9386
9403
  function ExportVarDec(state) {
9387
9404
  let eventData;
9388
9405
  if (state.events) {
@@ -18126,9 +18143,6 @@ ${input.slice(result.pos)}
18126
18143
  scopes.pop();
18127
18144
  }
18128
18145
  function createLetDecs(statements, scopes) {
18129
- function hasDec(name) {
18130
- return scopes.some((s) => s.has(name));
18131
- }
18132
18146
  function findVarDecs(statements2, decs) {
18133
18147
  const declarationNames = gatherRecursive(
18134
18148
  statements2,
@@ -18136,52 +18150,68 @@ ${input.slice(result.pos)}
18136
18150
  ).filter((node) => node.type === "Declaration").flatMap((node) => node.names);
18137
18151
  return new Set(declarationNames);
18138
18152
  }
18139
- function insertBeforeAssignment(assignment, content) {
18140
- if (assignment.children && assignment.children.length) {
18141
- let indent = assignment.children[0][0][0];
18142
- if (Array.isArray(indent))
18143
- indent = indent[indent.length - 1];
18144
- assignment.children.unshift([indent, ...content]);
18145
- }
18153
+ let declaredIdentifiers = findVarDecs(statements);
18154
+ function hasDec(name) {
18155
+ return declaredIdentifiers.has(name) || scopes.some((s) => s.has(name));
18156
+ }
18157
+ function gatherBlockOrOther(statement) {
18158
+ return gatherNodes(statement, (s) => s.type === "BlockStatement" || s.type === "AssignmentExpression" || s.type === "Declaration").flatMap((node) => {
18159
+ if (node.type == "BlockStatement")
18160
+ return node.bare ? gatherBlockOrOther(node.expressions) : node;
18161
+ else if (node.children && node.children.length)
18162
+ return [...gatherBlockOrOther(node.children), node];
18163
+ else
18164
+ return [];
18165
+ });
18146
18166
  }
18147
18167
  let currentScope = /* @__PURE__ */ new Set();
18148
18168
  scopes.push(currentScope);
18149
18169
  const fnNodes = gatherNodes(statements, (s) => s.type === "FunctionExpression");
18150
18170
  const forNodes = gatherNodes(statements, (s) => s.type === "ForStatement");
18151
- const nodes = gatherNodes(statements, (s) => s.type === "BlockStatement" || s.type === "AssignmentExpression" || s.type === "Declaration");
18152
- let declaredIdentifiers = findVarDecs(statements);
18153
- for (const node of nodes) {
18154
- if (node.type == "AssignmentExpression") {
18155
- let undeclaredIdentifiers = node.names.filter((name) => !(hasDec(name) || declaredIdentifiers.has(name)));
18156
- if (node.children.length)
18157
- createLetDecs(node.children, scopes);
18158
- undeclaredIdentifiers.forEach((name) => currentScope.add(name));
18159
- if (node.names.length === undeclaredIdentifiers.length) {
18160
- insertBeforeAssignment(node, ["let "]);
18161
- } else if (undeclaredIdentifiers.length > 0) {
18162
- insertBeforeAssignment(node, ["let ", undeclaredIdentifiers.join(", "), "\n"]);
18171
+ let targetStatements = [];
18172
+ for (const statement of statements) {
18173
+ const nodes = gatherBlockOrOther(statement);
18174
+ let undeclaredIdentifiers = [];
18175
+ for (const node of nodes) {
18176
+ if (node.type == "BlockStatement") {
18177
+ let block = node;
18178
+ let fnNode = fnNodes.find((fnNode2) => fnNode2.block === block);
18179
+ let forNode = forNodes.find((forNode2) => forNode2.block === block);
18180
+ if (fnNode != null) {
18181
+ scopes.push(new Set(fnNode.parameters.names));
18182
+ createLetDecs(block.expressions, scopes);
18183
+ scopes.pop();
18184
+ } else if (forNode != null) {
18185
+ scopes.push(new Set(forNode.declaration.names));
18186
+ createLetDecs(block.expressions, scopes);
18187
+ scopes.pop();
18188
+ } else
18189
+ createLetDecs(block.expressions, scopes);
18190
+ continue;
18191
+ }
18192
+ if (node.names == null)
18193
+ continue;
18194
+ let names = node.names.filter((name) => !hasDec(name));
18195
+ if (node.type == "AssignmentExpression")
18196
+ undeclaredIdentifiers.push(...names);
18197
+ names.forEach((name) => currentScope.add(name));
18198
+ }
18199
+ if (undeclaredIdentifiers.length > 0) {
18200
+ let indent = statement[0];
18201
+ let firstIdentifier = gatherNodes(statement[1], (node) => node.type == "Identifier")[0];
18202
+ if (undeclaredIdentifiers.length == 1 && statement[1].type == "AssignmentExpression" && statement[1].names.length == 1 && statement[1].names[0] == undeclaredIdentifiers[0] && firstIdentifier && firstIdentifier.names == undeclaredIdentifiers[0] && gatherNodes(statement[1], (node) => node.type === "ObjectBindingPattern").length == 0)
18203
+ statement[1].children.unshift(["let "]);
18204
+ else {
18205
+ let tail = "\n";
18206
+ if (gatherNodes(indent, (node) => node.token && node.token.endsWith("\n")).length > 0)
18207
+ tail = void 0;
18208
+ targetStatements.push([indent, "let ", undeclaredIdentifiers.join(", "), tail]);
18163
18209
  }
18164
- } else if (node.type == "Declaration") {
18165
- if (node.children && node.children.length)
18166
- createLetDecs(node.children, scopes);
18167
- node.names.forEach((name) => currentScope.add(name));
18168
- } else {
18169
- let block = node;
18170
- let fnNode = fnNodes.find((fnNode2) => fnNode2.block === block);
18171
- let forNode = forNodes.find((forNode2) => forNode2.block === block);
18172
- if (fnNode != null) {
18173
- scopes.push(new Set(fnNode.parameters.names));
18174
- createLetDecs(block.expressions, scopes);
18175
- scopes.pop();
18176
- } else if (forNode != null) {
18177
- scopes.push(new Set(forNode.declaration.names));
18178
- createLetDecs(block.expressions, scopes);
18179
- scopes.pop();
18180
- } else
18181
- createLetDecs(block.expressions, scopes);
18182
18210
  }
18211
+ targetStatements.push(statement);
18183
18212
  }
18184
18213
  scopes.pop();
18214
+ statements.splice(0, statements.length, targetStatements);
18185
18215
  }
18186
18216
  function gatherBindingCode(statements, opts) {
18187
18217
  const thisAssignments = [];
@@ -18889,7 +18919,7 @@ var uncacheable;
18889
18919
  ({ parse } = import_parser.default);
18890
18920
  ({ SourceMap: SourceMap2, base64Encode: base64Encode2 } = util_exports);
18891
18921
  defaultOptions = {};
18892
- uncacheable = /* @__PURE__ */ new Set(["ActualAssignment", "ApplicationStart", "Arguments", "ArgumentsWithTrailingMemberExpressions", "ArrowFunction", "ArrowFunctionTail", "AssignmentExpression", "AssignmentExpressionTail", "BinaryOpExpression", "BinaryOpRHS", "BracedBlock", "BracedObjectLiteralContent", "BracedOrEmptyBlock", "CallExpression", "CallExpressionRest", "CoffeeCommentEnabled", "CommaDelimiter", "ConditionalExpression", "Declaration", "Debugger", "ElseClause", "Expression", "ExpressionStatement", "ExpressionWithIndentedApplicationSuppressed", "ExtendedExpression", "FatArrowBody", "FunctionDeclaration", "FunctionExpression", "HoistableDeclaration", "ImplicitArguments", "ImplicitInlineObjectPropertyDelimiter", "ImplicitNestedBlock", "IndentedApplicationAllowed", "IndentedFurther", "IndentedJSXChildExpression", "InlineObjectLiteral", "InsertIndent", "JSXChild", "JSXChildren", "JSXElement", "JSXFragment", "JSXImplicitFragment", "JSXMixedChildren", "JSXNested", "JSXNestedChildren", "JSXOptionalClosingElement", "JSXOptionalClosingFragment", "JSXTag", "LeftHandSideExpression", "MemberExpression", "MemberExpressionRest", "Nested", "NestedBindingElement", "NestedBindingElements", "NestedBlockExpression", "NestedBlockExpression", "NestedBlockStatement", "NestedBlockStatements", "NestedElement", "NestedElementList", "NestedImplicitObjectLiteral", "NestedImplicitPropertyDefinition", "NestedImplicitPropertyDefinitions", "NestedInterfaceProperty", "NestedJSXChildExpression", "NestedObject", "NestedPropertyDefinitions", "NonSuppressedTrailingMemberExpressions", "ObjectLiteral", "PopIndent", "PrimaryExpression", "PushIndent", "PushJSXOpeningElement", "PushJSXOpeningFragment", "Samedent", "ShortCircuitExpression", "SingleLineComment", "SingleLineStatements", "SnugNamedProperty", "Statement", "StatementListItem", "SuppressIndentedApplication", "SuppressTrailingMemberProperty", "ThinArrowFunction", "TrackIndented", "TrailingMemberExpressions", "TrailingMemberPropertyAllowed", "TypedJSXElement", "TypedJSXFragment", "UnaryExpression", "UpdateExpression"]);
18922
+ uncacheable = /* @__PURE__ */ new Set(["ActualAssignment", "ApplicationStart", "Arguments", "ArgumentsWithTrailingMemberExpressions", "ArrowFunction", "ArrowFunctionTail", "AssignmentExpression", "AssignmentExpressionTail", "BinaryOpExpression", "BinaryOpRHS", "BracedBlock", "BracedObjectLiteralContent", "BracedOrEmptyBlock", "CallExpression", "CallExpressionRest", "CoffeeCommentEnabled", "CommaDelimiter", "ConditionalExpression", "Declaration", "Debugger", "ElseClause", "Expression", "ExpressionStatement", "ExpressionWithIndentedApplicationSuppressed", "ExtendedExpression", "FatArrowBody", "FunctionDeclaration", "FunctionExpression", "HoistableDeclaration", "ImplicitArguments", "ImplicitInlineObjectPropertyDelimiter", "ImplicitNestedBlock", "IndentedApplicationAllowed", "IndentedFurther", "IndentedJSXChildExpression", "InlineObjectLiteral", "InsertIndent", "JSXChild", "JSXChildren", "JSXElement", "JSXFragment", "JSXImplicitFragment", "JSXMixedChildren", "JSXNested", "JSXNestedChildren", "JSXOptionalClosingElement", "JSXOptionalClosingFragment", "JSXTag", "LeftHandSideExpression", "MemberExpression", "MemberExpressionRest", "Nested", "NestedBindingElement", "NestedBindingElements", "NestedBlockExpression", "NestedBlockExpression", "NestedBlockStatement", "NestedBlockStatements", "NestedElement", "NestedElementList", "NestedImplicitObjectLiteral", "NestedImplicitPropertyDefinition", "NestedImplicitPropertyDefinitions", "NestedInterfaceProperty", "NestedJSXChildExpression", "NestedObject", "NestedPropertyDefinitions", "NonSuppressedTrailingMemberExpressions", "ObjectLiteral", "PopIndent", "PrimaryExpression", "PushIndent", "PushJSXOpeningElement", "PushJSXOpeningFragment", "Samedent", "ShortCircuitExpression", "SingleLineAssignmentExpression", "SingleLineComment", "SingleLineStatements", "SnugNamedProperty", "Statement", "StatementListItem", "SuppressIndentedApplication", "SuppressTrailingMemberProperty", "ThinArrowFunction", "TrackIndented", "TrailingMemberExpressions", "TrailingMemberPropertyAllowed", "TypedJSXElement", "TypedJSXFragment", "UnaryExpression", "UpdateExpression"]);
18893
18923
  var compile = function(src, options = defaultOptions) {
18894
18924
  var ast, code, events, filename, sm, srcMapJSON;
18895
18925
  filename = options.filename || "unknown";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@danielx/civet",
3
- "version": "0.5.53",
3
+ "version": "0.5.54",
4
4
  "description": "CoffeeScript style syntax for TypeScript",
5
5
  "main": "dist/main.js",
6
6
  "module": "dist/main.mjs",