astro-eslint-parser 1.0.1 → 1.0.3

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/lib/index.js CHANGED
@@ -57,7 +57,7 @@ var KEYS = (0, import_eslint_visitor_keys.unionWith)(
57
57
  );
58
58
 
59
59
  // src/parser/index.ts
60
- var import_types2 = require("@typescript-eslint/types");
60
+ var import_types3 = require("@typescript-eslint/types");
61
61
 
62
62
  // src/debug.ts
63
63
  var import_debug = __toESM(require("debug"));
@@ -123,8 +123,7 @@ var TSService = class {
123
123
  filePath: normalized
124
124
  };
125
125
  for (const { filePath: targetPath } of [this.currTarget, lastTarget]) {
126
- if (!targetPath)
127
- continue;
126
+ if (!targetPath) continue;
128
127
  this.fileWatchCallbacks.get(targetPath)?.update();
129
128
  }
130
129
  const program = this.watch.getProgram().getProgram();
@@ -496,12 +495,10 @@ function getTSParserNameFromObject(value) {
496
495
  return null;
497
496
  }
498
497
  function isTSESLintParserObject(value) {
499
- if (!isEnhancedParserObject(value))
500
- return false;
498
+ if (!isEnhancedParserObject(value)) return false;
501
499
  if (value.name === "typescript-eslint-parser-for-extra-files")
502
500
  return true;
503
- if (value.meta?.name === "typescript-eslint/parser")
504
- return true;
501
+ if (value.meta?.name === "typescript-eslint/parser") return true;
505
502
  try {
506
503
  const result = value.parseForESLint("", {});
507
504
  const services = result.services;
@@ -514,7 +511,8 @@ function isTSESLintParserObject(value) {
514
511
  }
515
512
 
516
513
  // src/parser/script.ts
517
- var import_scope_manager = require("@typescript-eslint/scope-manager");
514
+ var import_types = require("@typescript-eslint/types");
515
+ var import_scope_manager2 = require("@typescript-eslint/scope-manager");
518
516
  var import_eslint_scope = require("eslint-scope");
519
517
 
520
518
  // src/traverse.ts
@@ -558,6 +556,298 @@ function traverseNodes(node, visitor) {
558
556
  traverse(node, null, visitor);
559
557
  }
560
558
 
559
+ // src/parser/scope/index.ts
560
+ var import_scope_manager = require("@typescript-eslint/scope-manager");
561
+
562
+ // src/util/index.ts
563
+ function sortedLastIndex(array, compare) {
564
+ let lower = 0;
565
+ let upper = array.length;
566
+ while (lower < upper) {
567
+ const mid = Math.floor(lower + (upper - lower) / 2);
568
+ const target = compare(array[mid]);
569
+ if (target < 0) {
570
+ lower = mid + 1;
571
+ } else if (target > 0) {
572
+ upper = mid;
573
+ } else {
574
+ return mid + 1;
575
+ }
576
+ }
577
+ return upper;
578
+ }
579
+ function addElementToSortedArray(array, element, compare) {
580
+ const index = sortedLastIndex(array, (target) => compare(target, element));
581
+ array.splice(index, 0, element);
582
+ }
583
+ function addElementsToSortedArray(array, elements, compare) {
584
+ if (!elements.length) {
585
+ return;
586
+ }
587
+ let last = elements[0];
588
+ let index = sortedLastIndex(array, (target) => compare(target, last));
589
+ for (const element of elements) {
590
+ if (compare(last, element) > 0) {
591
+ index = sortedLastIndex(array, (target) => compare(target, element));
592
+ }
593
+ let e = array[index];
594
+ while (e && compare(e, element) <= 0) {
595
+ e = array[++index];
596
+ }
597
+ array.splice(index, 0, element);
598
+ last = element;
599
+ }
600
+ }
601
+
602
+ // src/parser/scope/index.ts
603
+ var READ_FLAG = 1;
604
+ var WRITE_FLAG = 2;
605
+ var READ_WRITE_FLAG = 3;
606
+ var REFERENCE_TYPE_VALUE_FLAG = 1;
607
+ var REFERENCE_TYPE_TYPE_FLAG = 2;
608
+ function getProgramScope(scopeManager) {
609
+ const globalScope = scopeManager.globalScope;
610
+ return globalScope.childScopes.find((s) => s.type === "module") || globalScope;
611
+ }
612
+ function removeAllScopeAndVariableAndReference(target, info) {
613
+ const targetScopes = /* @__PURE__ */ new Set();
614
+ traverseNodes(target, {
615
+ visitorKeys: info.visitorKeys,
616
+ enterNode(node) {
617
+ const scope = info.scopeManager.acquire(node);
618
+ if (scope) {
619
+ targetScopes.add(scope);
620
+ return;
621
+ }
622
+ if (node.type === "Identifier") {
623
+ let scope2 = getInnermostScopeFromNode(info.scopeManager, node);
624
+ while (scope2 && scope2.block.type !== "Program" && target.range[0] <= scope2.block.range[0] && scope2.block.range[1] <= target.range[1]) {
625
+ scope2 = scope2.upper;
626
+ }
627
+ if (targetScopes.has(scope2)) {
628
+ return;
629
+ }
630
+ removeIdentifierVariable(node, scope2);
631
+ removeIdentifierReference(node, scope2);
632
+ }
633
+ },
634
+ leaveNode() {
635
+ }
636
+ });
637
+ for (const scope of targetScopes) {
638
+ removeScope(info.scopeManager, scope);
639
+ }
640
+ }
641
+ function addVirtualReference(node, variable, scope, status) {
642
+ const reference = new import_scope_manager.Reference(
643
+ node,
644
+ scope,
645
+ status.write && status.read ? READ_WRITE_FLAG : status.write ? WRITE_FLAG : READ_FLAG,
646
+ void 0,
647
+ // writeExpr
648
+ void 0,
649
+ // maybeImplicitGlobal
650
+ void 0,
651
+ // init
652
+ status.typeRef ? REFERENCE_TYPE_TYPE_FLAG : REFERENCE_TYPE_VALUE_FLAG
653
+ );
654
+ reference.astroVirtualReference = true;
655
+ addReference(variable.references, reference);
656
+ reference.resolved = variable;
657
+ if (status.forceUsed) {
658
+ variable.eslintUsed = true;
659
+ }
660
+ return reference;
661
+ }
662
+ function addGlobalVariable(reference, scopeManager) {
663
+ const globalScope = scopeManager.globalScope;
664
+ const name2 = reference.identifier.name;
665
+ let variable = globalScope.set.get(name2);
666
+ if (!variable) {
667
+ variable = new import_scope_manager.Variable(name2, globalScope);
668
+ globalScope.variables.push(variable);
669
+ globalScope.set.set(name2, variable);
670
+ }
671
+ reference.resolved = variable;
672
+ variable.references.push(reference);
673
+ return variable;
674
+ }
675
+ function removeReferenceFromThrough(reference, baseScope) {
676
+ const variable = reference.resolved;
677
+ const name2 = reference.identifier.name;
678
+ let scope = baseScope;
679
+ while (scope) {
680
+ for (const ref of [...scope.through]) {
681
+ if (reference === ref) {
682
+ scope.through.splice(scope.through.indexOf(ref), 1);
683
+ } else if (ref.identifier.name === name2) {
684
+ ref.resolved = variable;
685
+ if (!variable.references.includes(ref)) {
686
+ addReference(variable.references, ref);
687
+ }
688
+ scope.through.splice(scope.through.indexOf(ref), 1);
689
+ }
690
+ }
691
+ scope = scope.upper;
692
+ }
693
+ }
694
+ function removeScope(scopeManager, scope) {
695
+ for (const childScope of scope.childScopes) {
696
+ removeScope(scopeManager, childScope);
697
+ }
698
+ while (scope.references[0]) {
699
+ removeReference(scope.references[0], scope);
700
+ }
701
+ const upper = scope.upper;
702
+ if (upper) {
703
+ const index2 = upper.childScopes.indexOf(scope);
704
+ if (index2 >= 0) {
705
+ upper.childScopes.splice(index2, 1);
706
+ }
707
+ }
708
+ const index = scopeManager.scopes.indexOf(scope);
709
+ if (index >= 0) {
710
+ scopeManager.scopes.splice(index, 1);
711
+ }
712
+ }
713
+ function removeReference(reference, baseScope) {
714
+ if (reference.resolved) {
715
+ if (reference.resolved.defs.some((d) => d.name === reference.identifier)) {
716
+ const varIndex = baseScope.variables.indexOf(reference.resolved);
717
+ if (varIndex >= 0) {
718
+ baseScope.variables.splice(varIndex, 1);
719
+ }
720
+ const name2 = reference.identifier.name;
721
+ if (reference.resolved === baseScope.set.get(name2)) {
722
+ baseScope.set.delete(name2);
723
+ }
724
+ } else {
725
+ const refIndex = reference.resolved.references.indexOf(reference);
726
+ if (refIndex >= 0) {
727
+ reference.resolved.references.splice(refIndex, 1);
728
+ }
729
+ }
730
+ }
731
+ let scope = baseScope;
732
+ while (scope) {
733
+ const refIndex = scope.references.indexOf(reference);
734
+ if (refIndex >= 0) {
735
+ scope.references.splice(refIndex, 1);
736
+ }
737
+ const throughIndex = scope.through.indexOf(reference);
738
+ if (throughIndex >= 0) {
739
+ scope.through.splice(throughIndex, 1);
740
+ }
741
+ scope = scope.upper;
742
+ }
743
+ }
744
+ function removeIdentifierVariable(node, scope) {
745
+ for (let varIndex = 0; varIndex < scope.variables.length; varIndex++) {
746
+ const variable = scope.variables[varIndex];
747
+ const defIndex = variable.defs.findIndex((def) => def.name === node);
748
+ if (defIndex < 0) {
749
+ continue;
750
+ }
751
+ variable.defs.splice(defIndex, 1);
752
+ if (variable.defs.length === 0) {
753
+ referencesToThrough(variable.references, scope);
754
+ variable.references.forEach((r) => {
755
+ if (r.init) r.init = false;
756
+ r.resolved = null;
757
+ });
758
+ scope.variables.splice(varIndex, 1);
759
+ const name2 = node.name;
760
+ if (variable === scope.set.get(name2)) {
761
+ scope.set.delete(name2);
762
+ }
763
+ } else {
764
+ const idIndex = variable.identifiers.indexOf(node);
765
+ if (idIndex >= 0) {
766
+ variable.identifiers.splice(idIndex, 1);
767
+ }
768
+ }
769
+ return;
770
+ }
771
+ }
772
+ function removeIdentifierReference(node, scope) {
773
+ const reference = scope.references.find((ref) => ref.identifier === node);
774
+ if (reference) {
775
+ removeReference(reference, scope);
776
+ return true;
777
+ }
778
+ const location = node.range[0];
779
+ const pendingScopes = [];
780
+ for (const childScope of scope.childScopes) {
781
+ const range = childScope.block.range;
782
+ if (range[0] <= location && location < range[1]) {
783
+ if (removeIdentifierReference(node, childScope)) {
784
+ return true;
785
+ }
786
+ } else {
787
+ pendingScopes.push(childScope);
788
+ }
789
+ }
790
+ for (const childScope of pendingScopes) {
791
+ if (removeIdentifierReference(node, childScope)) {
792
+ return true;
793
+ }
794
+ }
795
+ return false;
796
+ }
797
+ function getInnermostScopeFromNode(scopeManager, currentNode) {
798
+ return getInnermostScope(
799
+ getScopeFromNode(scopeManager, currentNode),
800
+ currentNode
801
+ );
802
+ }
803
+ function getScopeFromNode(scopeManager, currentNode) {
804
+ let node = currentNode;
805
+ for (; node; node = node.parent || null) {
806
+ const scope = scopeManager.acquire(node, false);
807
+ if (scope) {
808
+ if (scope.type === "function-expression-name") {
809
+ return scope.childScopes[0];
810
+ }
811
+ if (scope.type === "global" && node.type === "Program" && node.sourceType === "module") {
812
+ return scope.childScopes.find((s) => s.type === "module") || scope;
813
+ }
814
+ return scope;
815
+ }
816
+ }
817
+ const global = scopeManager.globalScope;
818
+ return global;
819
+ }
820
+ function getInnermostScope(initialScope, node) {
821
+ for (const childScope of initialScope.childScopes) {
822
+ const range = childScope.block.range;
823
+ if (range[0] <= node.range[0] && node.range[1] <= range[1]) {
824
+ return getInnermostScope(childScope, node);
825
+ }
826
+ }
827
+ return initialScope;
828
+ }
829
+ function referencesToThrough(references, baseScope) {
830
+ let scope = baseScope;
831
+ while (scope) {
832
+ addAllReferences(scope.through, references);
833
+ scope = scope.upper;
834
+ }
835
+ }
836
+ function addAllReferences(list, elements) {
837
+ addElementsToSortedArray(
838
+ list,
839
+ elements,
840
+ (a, b) => a.identifier.range[0] - b.identifier.range[0]
841
+ );
842
+ }
843
+ function addReference(list, reference) {
844
+ addElementToSortedArray(
845
+ list,
846
+ reference,
847
+ (a, b) => a.identifier.range[0] - b.identifier.range[0]
848
+ );
849
+ }
850
+
561
851
  // src/parser/script.ts
562
852
  function parseScript(code, ctx, parserOptionsCtx) {
563
853
  const result = parseScriptInternal(code, ctx, parserOptionsCtx);
@@ -569,7 +859,7 @@ function parseScript(code, ctx, parserOptionsCtx) {
569
859
  }
570
860
  function analyzeScope(result, parserOptions) {
571
861
  try {
572
- return (0, import_scope_manager.analyze)(result.ast, {
862
+ return (0, import_scope_manager2.analyze)(result.ast, {
573
863
  globalReturn: parserOptions.ecmaFeatures?.globalReturn,
574
864
  jsxPragma: parserOptions.jsxPragma,
575
865
  jsxFragmentName: parserOptions.jsxFragmentName,
@@ -579,7 +869,7 @@ function analyzeScope(result, parserOptions) {
579
869
  } catch {
580
870
  }
581
871
  const ecmaFeatures = parserOptions.ecmaFeatures || {};
582
- return (0, import_eslint_scope.analyze)(result.ast, {
872
+ return analyzeForEcmaScript(result.ast, {
583
873
  ignoreEval: true,
584
874
  nodejsScope: ecmaFeatures.globalReturn,
585
875
  impliedStrict: ecmaFeatures.impliedStrict,
@@ -616,6 +906,73 @@ ${code}`
616
906
  patchResult?.terminate();
617
907
  }
618
908
  }
909
+ var Referencer = class extends import_eslint_scope.Referencer {
910
+ JSXAttribute(node) {
911
+ this.visit(node.value);
912
+ }
913
+ JSXClosingElement() {
914
+ }
915
+ JSXFragment(node) {
916
+ this.visitChildren(node);
917
+ }
918
+ JSXIdentifier(node) {
919
+ const scope = this.currentScope();
920
+ const ref = new import_scope_manager2.Reference(
921
+ node,
922
+ scope,
923
+ READ_FLAG,
924
+ void 0,
925
+ void 0,
926
+ false,
927
+ REFERENCE_TYPE_VALUE_FLAG
928
+ );
929
+ scope.references.push(ref);
930
+ scope.__left.push(ref);
931
+ }
932
+ JSXMemberExpression(node) {
933
+ if (node.object.type !== import_types.AST_NODE_TYPES.JSXIdentifier) {
934
+ this.visit(node.object);
935
+ } else {
936
+ if (node.object.name !== "this") {
937
+ this.visit(node.object);
938
+ }
939
+ }
940
+ }
941
+ JSXOpeningElement(node) {
942
+ if (node.name.type === import_types.AST_NODE_TYPES.JSXIdentifier) {
943
+ if (node.name.name[0].toUpperCase() === node.name.name[0] || node.name.name === "this") {
944
+ this.visit(node.name);
945
+ }
946
+ } else {
947
+ this.visit(node.name);
948
+ }
949
+ for (const attr of node.attributes) {
950
+ this.visit(attr);
951
+ }
952
+ }
953
+ };
954
+ function analyzeForEcmaScript(tree, providedOptions) {
955
+ const options = Object.assign(
956
+ {
957
+ optimistic: false,
958
+ nodejsScope: false,
959
+ impliedStrict: false,
960
+ sourceType: "script",
961
+ // one of ['script', 'module', 'commonjs']
962
+ ecmaVersion: 5,
963
+ childVisitorKeys: null,
964
+ fallback: "iteration"
965
+ },
966
+ providedOptions
967
+ );
968
+ const scopeManager = new import_eslint_scope.ScopeManager(
969
+ // @ts-expect-error -- No typings
970
+ options
971
+ );
972
+ const referencer = new Referencer(options, scopeManager);
973
+ referencer.visit(tree);
974
+ return scopeManager;
975
+ }
619
976
 
620
977
  // src/parser/sort.ts
621
978
  function sort(tokens) {
@@ -628,7 +985,7 @@ function sort(tokens) {
628
985
  }
629
986
 
630
987
  // src/parser/process-template.ts
631
- var import_types = require("@typescript-eslint/types");
988
+ var import_types2 = require("@typescript-eslint/types");
632
989
 
633
990
  // src/astro/index.ts
634
991
  var import_decode = require("entities/lib/decode.js");
@@ -800,12 +1157,9 @@ function getEndOffset(node, ctx) {
800
1157
  if (node.position.end?.offset != null) {
801
1158
  return node.position.end.offset;
802
1159
  }
803
- if (isTag(node))
804
- return calcTagEndOffset(node, ctx);
805
- if (node.type === "expression")
806
- return calcExpressionEndOffset(node, ctx);
807
- if (node.type === "comment")
808
- return calcCommentEndOffset(node, ctx);
1160
+ if (isTag(node)) return calcTagEndOffset(node, ctx);
1161
+ if (node.type === "expression") return calcExpressionEndOffset(node, ctx);
1162
+ if (node.type === "comment") return calcCommentEndOffset(node, ctx);
809
1163
  if (node.type === "frontmatter") {
810
1164
  const start = node.position.start.offset;
811
1165
  return ctx.code.indexOf("---", start + 3) + 3;
@@ -983,8 +1337,7 @@ function getTokenInfo(ctx, tokens, position) {
983
1337
  };
984
1338
  function getHTMLEntity(position3) {
985
1339
  let codeOffset2 = position3;
986
- if (ctx.code[codeOffset2++] !== "&")
987
- return null;
1340
+ if (ctx.code[codeOffset2++] !== "&") return null;
988
1341
  let entity = "";
989
1342
  const entityDecoder = new import_decode.EntityDecoder(
990
1343
  import_decode.htmlDecodeTree,
@@ -1272,7 +1625,7 @@ function processTemplate(ctx, resultTemplate) {
1272
1625
  script.appendVirtualScript("<>");
1273
1626
  fragmentOpened = true;
1274
1627
  script.restoreContext.addRestoreNodeProcess((scriptNode, { result }) => {
1275
- if (scriptNode.type === import_types.AST_NODE_TYPES.ExpressionStatement && scriptNode.expression.type === import_types.AST_NODE_TYPES.JSXFragment && scriptNode.range[0] === startOffset && result.ast.body.includes(scriptNode)) {
1628
+ if (scriptNode.type === import_types2.AST_NODE_TYPES.ExpressionStatement && scriptNode.expression.type === import_types2.AST_NODE_TYPES.JSXFragment && scriptNode.range[0] === startOffset && result.ast.body.includes(scriptNode)) {
1276
1629
  const index = result.ast.body.indexOf(scriptNode);
1277
1630
  const rootFragment = result.ast.body[index] = scriptNode.expression;
1278
1631
  delete rootFragment.closingFragment;
@@ -1310,7 +1663,7 @@ function processTemplate(ctx, resultTemplate) {
1310
1663
  (_scriptNode, { result }) => {
1311
1664
  for (let index = 0; index < result.ast.body.length; index++) {
1312
1665
  const st = result.ast.body[index];
1313
- if (st.type === import_types.AST_NODE_TYPES.EmptyStatement) {
1666
+ if (st.type === import_types2.AST_NODE_TYPES.EmptyStatement) {
1314
1667
  if (st.range[0] === scriptEnd && st.range[1] === scriptEnd) {
1315
1668
  result.ast.body.splice(index, 1);
1316
1669
  break;
@@ -1320,11 +1673,11 @@ function processTemplate(ctx, resultTemplate) {
1320
1673
  return true;
1321
1674
  }
1322
1675
  );
1323
- script.restoreContext.addToken(import_types.AST_TOKEN_TYPES.Punctuator, [
1676
+ script.restoreContext.addToken(import_types2.AST_TOKEN_TYPES.Punctuator, [
1324
1677
  node.position.start.offset,
1325
1678
  node.position.start.offset + 3
1326
1679
  ]);
1327
- script.restoreContext.addToken(import_types.AST_TOKEN_TYPES.Punctuator, [
1680
+ script.restoreContext.addToken(import_types2.AST_TOKEN_TYPES.Punctuator, [
1328
1681
  end - 3,
1329
1682
  end
1330
1683
  ]);
@@ -1342,7 +1695,7 @@ function processTemplate(ctx, resultTemplate) {
1342
1695
  script.appendOriginal(start2);
1343
1696
  script.appendVirtualScript("<>");
1344
1697
  script.restoreContext.addRestoreNodeProcess((scriptNode) => {
1345
- if (scriptNode.range[0] === start2 && scriptNode.type === import_types.AST_NODE_TYPES.JSXFragment) {
1698
+ if (scriptNode.range[0] === start2 && scriptNode.type === import_types2.AST_NODE_TYPES.JSXFragment) {
1346
1699
  delete scriptNode.openingFragment;
1347
1700
  delete scriptNode.closingFragment;
1348
1701
  const fragmentNode = scriptNode;
@@ -1384,7 +1737,7 @@ function processTemplate(ctx, resultTemplate) {
1384
1737
  script.appendVirtualScript('"');
1385
1738
  script.restoreContext.addRestoreNodeProcess(
1386
1739
  (scriptNode, context) => {
1387
- if (scriptNode.type === import_types.AST_NODE_TYPES.JSXAttribute && scriptNode.range[0] === attrStart) {
1740
+ if (scriptNode.type === import_types2.AST_NODE_TYPES.JSXAttribute && scriptNode.range[0] === attrStart) {
1388
1741
  const attrNode = scriptNode;
1389
1742
  if (attrNode.value?.type === "Literal" && typeof attrNode.value.value === "string") {
1390
1743
  const raw = ctx.code.slice(start2, end);
@@ -1403,7 +1756,7 @@ function processTemplate(ctx, resultTemplate) {
1403
1756
  const jsxName = /[\s"'[\]{}]/u.test(attr.name) ? generateUniqueId(attr.name) : attr.name;
1404
1757
  script.appendVirtualScript(`${jsxName}=`);
1405
1758
  script.restoreContext.addRestoreNodeProcess((scriptNode) => {
1406
- if (scriptNode.type === import_types.AST_NODE_TYPES.JSXAttribute && scriptNode.range[0] === start2) {
1759
+ if (scriptNode.type === import_types2.AST_NODE_TYPES.JSXAttribute && scriptNode.range[0] === start2) {
1407
1760
  const attrNode = scriptNode;
1408
1761
  attrNode.type = "AstroShorthandAttribute";
1409
1762
  const locs = ctx.getLocations(
@@ -1427,7 +1780,7 @@ function processTemplate(ctx, resultTemplate) {
1427
1780
  script.appendOriginal(end);
1428
1781
  script.appendVirtualScript("}");
1429
1782
  script.restoreContext.addRestoreNodeProcess((scriptNode) => {
1430
- if (scriptNode.type === import_types.AST_NODE_TYPES.JSXAttribute && scriptNode.range[0] === attrStart) {
1783
+ if (scriptNode.type === import_types2.AST_NODE_TYPES.JSXAttribute && scriptNode.range[0] === attrStart) {
1431
1784
  const attrNode = scriptNode;
1432
1785
  attrNode.type = "AstroTemplateLiteralAttribute";
1433
1786
  return true;
@@ -1449,7 +1802,7 @@ function processTemplate(ctx, resultTemplate) {
1449
1802
  script.appendOriginal(start2);
1450
1803
  script.skipOriginalOffset(text.value.length);
1451
1804
  script.restoreContext.addRestoreNodeProcess((scriptNode) => {
1452
- if (scriptNode.type === import_types.AST_NODE_TYPES.JSXElement && scriptNode.range[0] === styleNodeStart) {
1805
+ if (scriptNode.type === import_types2.AST_NODE_TYPES.JSXElement && scriptNode.range[0] === styleNodeStart) {
1453
1806
  const textNode = {
1454
1807
  type: "AstroRawText",
1455
1808
  value: text.value,
@@ -1462,7 +1815,7 @@ function processTemplate(ctx, resultTemplate) {
1462
1815
  }
1463
1816
  return false;
1464
1817
  });
1465
- script.restoreContext.addToken(import_types.AST_TOKEN_TYPES.JSXText, [
1818
+ script.restoreContext.addToken(import_types2.AST_TOKEN_TYPES.JSXText, [
1466
1819
  start2,
1467
1820
  start2 + text.value.length
1468
1821
  ]);
@@ -1481,7 +1834,7 @@ function processTemplate(ctx, resultTemplate) {
1481
1834
  script.skipOriginalOffset(length - 2);
1482
1835
  script.appendOriginal(end);
1483
1836
  script.restoreContext.addRestoreNodeProcess((scriptNode, context) => {
1484
- if (scriptNode.range[0] === start && scriptNode.type === import_types.AST_NODE_TYPES.JSXFragment) {
1837
+ if (scriptNode.range[0] === start && scriptNode.type === import_types2.AST_NODE_TYPES.JSXFragment) {
1485
1838
  delete scriptNode.children;
1486
1839
  delete scriptNode.openingFragment;
1487
1840
  delete scriptNode.closingFragment;
@@ -1516,7 +1869,7 @@ function processTemplate(ctx, resultTemplate) {
1516
1869
  script.skipOriginalOffset(length - 2);
1517
1870
  script.appendOriginal(end);
1518
1871
  script.restoreContext.addRestoreNodeProcess((scriptNode, context) => {
1519
- if (scriptNode.range[0] === start && scriptNode.type === import_types.AST_NODE_TYPES.JSXFragment) {
1872
+ if (scriptNode.range[0] === start && scriptNode.type === import_types2.AST_NODE_TYPES.JSXFragment) {
1520
1873
  delete scriptNode.children;
1521
1874
  delete scriptNode.openingFragment;
1522
1875
  delete scriptNode.closingFragment;
@@ -1557,7 +1910,7 @@ function processTemplate(ctx, resultTemplate) {
1557
1910
  script.restoreContext.addRestoreNodeProcess(
1558
1911
  (scriptNode, context) => {
1559
1912
  const parent2 = context.getParent(scriptNode);
1560
- if (scriptNode.range[0] === offset && scriptNode.type === import_types.AST_NODE_TYPES.JSXClosingElement && parent2.type === import_types.AST_NODE_TYPES.JSXElement) {
1913
+ if (scriptNode.range[0] === offset && scriptNode.type === import_types2.AST_NODE_TYPES.JSXClosingElement && parent2.type === import_types2.AST_NODE_TYPES.JSXElement) {
1561
1914
  parent2.closingElement = null;
1562
1915
  return true;
1563
1916
  }
@@ -1614,32 +1967,32 @@ function processTemplate(ctx, resultTemplate) {
1614
1967
  }
1615
1968
  if (colonOffset != null) {
1616
1969
  const punctuatorIndex = start + colonOffset;
1617
- script.restoreContext.addToken(import_types.AST_TOKEN_TYPES.JSXIdentifier, [
1970
+ script.restoreContext.addToken(import_types2.AST_TOKEN_TYPES.JSXIdentifier, [
1618
1971
  start,
1619
1972
  punctuatorIndex
1620
1973
  ]);
1621
- script.restoreContext.addToken(import_types.AST_TOKEN_TYPES.Punctuator, [
1974
+ script.restoreContext.addToken(import_types2.AST_TOKEN_TYPES.Punctuator, [
1622
1975
  punctuatorIndex,
1623
1976
  punctuatorIndex + 1
1624
1977
  ]);
1625
- script.restoreContext.addToken(import_types.AST_TOKEN_TYPES.JSXIdentifier, [
1978
+ script.restoreContext.addToken(import_types2.AST_TOKEN_TYPES.JSXIdentifier, [
1626
1979
  punctuatorIndex + 1,
1627
1980
  start + attr.name.length
1628
1981
  ]);
1629
1982
  } else {
1630
- script.restoreContext.addToken(import_types.AST_TOKEN_TYPES.JSXIdentifier, [
1983
+ script.restoreContext.addToken(import_types2.AST_TOKEN_TYPES.JSXIdentifier, [
1631
1984
  start,
1632
1985
  start + attr.name.length
1633
1986
  ]);
1634
1987
  }
1635
1988
  script.restoreContext.addRestoreNodeProcess((scriptNode, context) => {
1636
- if (scriptNode.type === import_types.AST_NODE_TYPES.JSXAttribute && scriptNode.range[0] === targetIndex) {
1989
+ if (scriptNode.type === import_types2.AST_NODE_TYPES.JSXAttribute && scriptNode.range[0] === targetIndex) {
1637
1990
  const baseNameNode = scriptNode.name;
1638
1991
  if (colonOffset != null) {
1639
1992
  const nameNode = baseNameNode;
1640
- nameNode.type = import_types.AST_NODE_TYPES.JSXNamespacedName;
1993
+ nameNode.type = import_types2.AST_NODE_TYPES.JSXNamespacedName;
1641
1994
  nameNode.namespace = {
1642
- type: import_types.AST_NODE_TYPES.JSXIdentifier,
1995
+ type: import_types2.AST_NODE_TYPES.JSXIdentifier,
1643
1996
  name: attr.name.slice(0, colonOffset),
1644
1997
  ...ctx.getLocations(
1645
1998
  baseNameNode.range[0],
@@ -1647,7 +2000,7 @@ function processTemplate(ctx, resultTemplate) {
1647
2000
  )
1648
2001
  };
1649
2002
  nameNode.name = {
1650
- type: import_types.AST_NODE_TYPES.JSXIdentifier,
2003
+ type: import_types2.AST_NODE_TYPES.JSXIdentifier,
1651
2004
  name: attr.name.slice(colonOffset + 1),
1652
2005
  ...ctx.getLocations(
1653
2006
  baseNameNode.range[0] + colonOffset + 1,
@@ -1658,7 +2011,7 @@ function processTemplate(ctx, resultTemplate) {
1658
2011
  nameNode.namespace.parent = nameNode;
1659
2012
  nameNode.name.parent = nameNode;
1660
2013
  } else {
1661
- if (baseNameNode.type === import_types.AST_NODE_TYPES.JSXIdentifier) {
2014
+ if (baseNameNode.type === import_types2.AST_NODE_TYPES.JSXIdentifier) {
1662
2015
  const nameNode = baseNameNode;
1663
2016
  nameNode.name = attr.name;
1664
2017
  scriptNode.name = nameNode;
@@ -1684,54 +2037,14 @@ function processTemplate(ctx, resultTemplate) {
1684
2037
  }
1685
2038
  return false;
1686
2039
  });
1687
- }
1688
- function generateUniqueId(base) {
1689
- let candidate = `$_${base.replace(/\W/g, "_")}${uniqueIdSeq++}`;
1690
- while (usedUniqueIds.has(candidate) || ctx.code.includes(candidate)) {
1691
- candidate = `$_${base.replace(/\W/g, "_")}${uniqueIdSeq++}`;
1692
- }
1693
- usedUniqueIds.add(candidate);
1694
- return candidate;
1695
- }
1696
- }
1697
-
1698
- // src/util/index.ts
1699
- function sortedLastIndex(array, compare) {
1700
- let lower = 0;
1701
- let upper = array.length;
1702
- while (lower < upper) {
1703
- const mid = Math.floor(lower + (upper - lower) / 2);
1704
- const target = compare(array[mid]);
1705
- if (target < 0) {
1706
- lower = mid + 1;
1707
- } else if (target > 0) {
1708
- upper = mid;
1709
- } else {
1710
- return mid + 1;
1711
- }
1712
- }
1713
- return upper;
1714
- }
1715
- function addElementToSortedArray(array, element, compare) {
1716
- const index = sortedLastIndex(array, (target) => compare(target, element));
1717
- array.splice(index, 0, element);
1718
- }
1719
- function addElementsToSortedArray(array, elements, compare) {
1720
- if (!elements.length) {
1721
- return;
1722
- }
1723
- let last = elements[0];
1724
- let index = sortedLastIndex(array, (target) => compare(target, last));
1725
- for (const element of elements) {
1726
- if (compare(last, element) > 0) {
1727
- index = sortedLastIndex(array, (target) => compare(target, element));
1728
- }
1729
- let e = array[index];
1730
- while (e && compare(e, element) <= 0) {
1731
- e = array[++index];
2040
+ }
2041
+ function generateUniqueId(base) {
2042
+ let candidate = `$_${base.replace(/\W/g, "_")}${uniqueIdSeq++}`;
2043
+ while (usedUniqueIds.has(candidate) || ctx.code.includes(candidate)) {
2044
+ candidate = `$_${base.replace(/\W/g, "_")}${uniqueIdSeq++}`;
1732
2045
  }
1733
- array.splice(index, 0, element);
1734
- last = element;
2046
+ usedUniqueIds.add(candidate);
2047
+ return candidate;
1735
2048
  }
1736
2049
  }
1737
2050
 
@@ -2363,257 +2676,6 @@ var ParserOptionsContext = class {
2363
2676
  }
2364
2677
  };
2365
2678
 
2366
- // src/parser/scope/index.ts
2367
- var import_scope_manager2 = require("@typescript-eslint/scope-manager");
2368
- var READ_FLAG = 1;
2369
- var WRITE_FLAG = 2;
2370
- var READ_WRITE_FLAG = 3;
2371
- var REFERENCE_TYPE_VALUE_FLAG = 1;
2372
- var REFERENCE_TYPE_TYPE_FLAG = 2;
2373
- function getProgramScope(scopeManager) {
2374
- const globalScope = scopeManager.globalScope;
2375
- return globalScope.childScopes.find((s) => s.type === "module") || globalScope;
2376
- }
2377
- function removeAllScopeAndVariableAndReference(target, info) {
2378
- const targetScopes = /* @__PURE__ */ new Set();
2379
- traverseNodes(target, {
2380
- visitorKeys: info.visitorKeys,
2381
- enterNode(node) {
2382
- const scope = info.scopeManager.acquire(node);
2383
- if (scope) {
2384
- targetScopes.add(scope);
2385
- return;
2386
- }
2387
- if (node.type === "Identifier") {
2388
- let scope2 = getInnermostScopeFromNode(info.scopeManager, node);
2389
- while (scope2 && scope2.block.type !== "Program" && target.range[0] <= scope2.block.range[0] && scope2.block.range[1] <= target.range[1]) {
2390
- scope2 = scope2.upper;
2391
- }
2392
- if (targetScopes.has(scope2)) {
2393
- return;
2394
- }
2395
- removeIdentifierVariable(node, scope2);
2396
- removeIdentifierReference(node, scope2);
2397
- }
2398
- },
2399
- leaveNode() {
2400
- }
2401
- });
2402
- for (const scope of targetScopes) {
2403
- removeScope(info.scopeManager, scope);
2404
- }
2405
- }
2406
- function addVirtualReference(node, variable, scope, status) {
2407
- const reference = new import_scope_manager2.Reference(
2408
- node,
2409
- scope,
2410
- status.write && status.read ? READ_WRITE_FLAG : status.write ? WRITE_FLAG : READ_FLAG,
2411
- void 0,
2412
- // writeExpr
2413
- void 0,
2414
- // maybeImplicitGlobal
2415
- void 0,
2416
- // init
2417
- status.typeRef ? REFERENCE_TYPE_TYPE_FLAG : REFERENCE_TYPE_VALUE_FLAG
2418
- );
2419
- reference.astroVirtualReference = true;
2420
- addReference(variable.references, reference);
2421
- reference.resolved = variable;
2422
- if (status.forceUsed) {
2423
- variable.eslintUsed = true;
2424
- }
2425
- return reference;
2426
- }
2427
- function addGlobalVariable(reference, scopeManager) {
2428
- const globalScope = scopeManager.globalScope;
2429
- const name2 = reference.identifier.name;
2430
- let variable = globalScope.set.get(name2);
2431
- if (!variable) {
2432
- variable = new import_scope_manager2.Variable(name2, globalScope);
2433
- globalScope.variables.push(variable);
2434
- globalScope.set.set(name2, variable);
2435
- }
2436
- reference.resolved = variable;
2437
- variable.references.push(reference);
2438
- return variable;
2439
- }
2440
- function removeReferenceFromThrough(reference, baseScope) {
2441
- const variable = reference.resolved;
2442
- const name2 = reference.identifier.name;
2443
- let scope = baseScope;
2444
- while (scope) {
2445
- for (const ref of [...scope.through]) {
2446
- if (reference === ref) {
2447
- scope.through.splice(scope.through.indexOf(ref), 1);
2448
- } else if (ref.identifier.name === name2) {
2449
- ref.resolved = variable;
2450
- if (!variable.references.includes(ref)) {
2451
- addReference(variable.references, ref);
2452
- }
2453
- scope.through.splice(scope.through.indexOf(ref), 1);
2454
- }
2455
- }
2456
- scope = scope.upper;
2457
- }
2458
- }
2459
- function removeScope(scopeManager, scope) {
2460
- for (const childScope of scope.childScopes) {
2461
- removeScope(scopeManager, childScope);
2462
- }
2463
- while (scope.references[0]) {
2464
- removeReference(scope.references[0], scope);
2465
- }
2466
- const upper = scope.upper;
2467
- if (upper) {
2468
- const index2 = upper.childScopes.indexOf(scope);
2469
- if (index2 >= 0) {
2470
- upper.childScopes.splice(index2, 1);
2471
- }
2472
- }
2473
- const index = scopeManager.scopes.indexOf(scope);
2474
- if (index >= 0) {
2475
- scopeManager.scopes.splice(index, 1);
2476
- }
2477
- }
2478
- function removeReference(reference, baseScope) {
2479
- if (reference.resolved) {
2480
- if (reference.resolved.defs.some((d) => d.name === reference.identifier)) {
2481
- const varIndex = baseScope.variables.indexOf(reference.resolved);
2482
- if (varIndex >= 0) {
2483
- baseScope.variables.splice(varIndex, 1);
2484
- }
2485
- const name2 = reference.identifier.name;
2486
- if (reference.resolved === baseScope.set.get(name2)) {
2487
- baseScope.set.delete(name2);
2488
- }
2489
- } else {
2490
- const refIndex = reference.resolved.references.indexOf(reference);
2491
- if (refIndex >= 0) {
2492
- reference.resolved.references.splice(refIndex, 1);
2493
- }
2494
- }
2495
- }
2496
- let scope = baseScope;
2497
- while (scope) {
2498
- const refIndex = scope.references.indexOf(reference);
2499
- if (refIndex >= 0) {
2500
- scope.references.splice(refIndex, 1);
2501
- }
2502
- const throughIndex = scope.through.indexOf(reference);
2503
- if (throughIndex >= 0) {
2504
- scope.through.splice(throughIndex, 1);
2505
- }
2506
- scope = scope.upper;
2507
- }
2508
- }
2509
- function removeIdentifierVariable(node, scope) {
2510
- for (let varIndex = 0; varIndex < scope.variables.length; varIndex++) {
2511
- const variable = scope.variables[varIndex];
2512
- const defIndex = variable.defs.findIndex((def) => def.name === node);
2513
- if (defIndex < 0) {
2514
- continue;
2515
- }
2516
- variable.defs.splice(defIndex, 1);
2517
- if (variable.defs.length === 0) {
2518
- referencesToThrough(variable.references, scope);
2519
- variable.references.forEach((r) => {
2520
- if (r.init)
2521
- r.init = false;
2522
- r.resolved = null;
2523
- });
2524
- scope.variables.splice(varIndex, 1);
2525
- const name2 = node.name;
2526
- if (variable === scope.set.get(name2)) {
2527
- scope.set.delete(name2);
2528
- }
2529
- } else {
2530
- const idIndex = variable.identifiers.indexOf(node);
2531
- if (idIndex >= 0) {
2532
- variable.identifiers.splice(idIndex, 1);
2533
- }
2534
- }
2535
- return;
2536
- }
2537
- }
2538
- function removeIdentifierReference(node, scope) {
2539
- const reference = scope.references.find((ref) => ref.identifier === node);
2540
- if (reference) {
2541
- removeReference(reference, scope);
2542
- return true;
2543
- }
2544
- const location = node.range[0];
2545
- const pendingScopes = [];
2546
- for (const childScope of scope.childScopes) {
2547
- const range = childScope.block.range;
2548
- if (range[0] <= location && location < range[1]) {
2549
- if (removeIdentifierReference(node, childScope)) {
2550
- return true;
2551
- }
2552
- } else {
2553
- pendingScopes.push(childScope);
2554
- }
2555
- }
2556
- for (const childScope of pendingScopes) {
2557
- if (removeIdentifierReference(node, childScope)) {
2558
- return true;
2559
- }
2560
- }
2561
- return false;
2562
- }
2563
- function getInnermostScopeFromNode(scopeManager, currentNode) {
2564
- return getInnermostScope(
2565
- getScopeFromNode(scopeManager, currentNode),
2566
- currentNode
2567
- );
2568
- }
2569
- function getScopeFromNode(scopeManager, currentNode) {
2570
- let node = currentNode;
2571
- for (; node; node = node.parent || null) {
2572
- const scope = scopeManager.acquire(node, false);
2573
- if (scope) {
2574
- if (scope.type === "function-expression-name") {
2575
- return scope.childScopes[0];
2576
- }
2577
- if (scope.type === "global" && node.type === "Program" && node.sourceType === "module") {
2578
- return scope.childScopes.find((s) => s.type === "module") || scope;
2579
- }
2580
- return scope;
2581
- }
2582
- }
2583
- const global = scopeManager.globalScope;
2584
- return global;
2585
- }
2586
- function getInnermostScope(initialScope, node) {
2587
- for (const childScope of initialScope.childScopes) {
2588
- const range = childScope.block.range;
2589
- if (range[0] <= node.range[0] && node.range[1] <= range[1]) {
2590
- return getInnermostScope(childScope, node);
2591
- }
2592
- }
2593
- return initialScope;
2594
- }
2595
- function referencesToThrough(references, baseScope) {
2596
- let scope = baseScope;
2597
- while (scope) {
2598
- addAllReferences(scope.through, references);
2599
- scope = scope.upper;
2600
- }
2601
- }
2602
- function addAllReferences(list, elements) {
2603
- addElementsToSortedArray(
2604
- list,
2605
- elements,
2606
- (a, b) => a.identifier.range[0] - b.identifier.range[0]
2607
- );
2608
- }
2609
- function addReference(list, reference) {
2610
- addElementToSortedArray(
2611
- list,
2612
- reference,
2613
- (a, b) => a.identifier.range[0] - b.identifier.range[0]
2614
- );
2615
- }
2616
-
2617
2679
  // src/parser/index.ts
2618
2680
  function parseForESLint(code, options) {
2619
2681
  const { result: resultTemplate, context: ctx } = parseTemplate(
@@ -2700,11 +2762,11 @@ function extractTokens(ast, ctx) {
2700
2762
  }
2701
2763
  if (isPunctuator(c)) {
2702
2764
  ast.ast.tokens.push(
2703
- ctx.buildToken(import_types2.AST_TOKEN_TYPES.Punctuator, [index, index + 1])
2765
+ ctx.buildToken(import_types3.AST_TOKEN_TYPES.Punctuator, [index, index + 1])
2704
2766
  );
2705
2767
  } else {
2706
2768
  ast.ast.tokens.push(
2707
- ctx.buildToken(import_types2.AST_TOKEN_TYPES.Identifier, [index, index + 1])
2769
+ ctx.buildToken(import_types3.AST_TOKEN_TYPES.Identifier, [index, index + 1])
2708
2770
  );
2709
2771
  }
2710
2772
  }
@@ -2748,7 +2810,7 @@ __export(meta_exports, {
2748
2810
 
2749
2811
  // package.json
2750
2812
  var name = "astro-eslint-parser";
2751
- var version = "1.0.1";
2813
+ var version = "1.0.3";
2752
2814
 
2753
2815
  // src/index.ts
2754
2816
  function parseForESLint2(code, options) {