astro-eslint-parser 1.0.1 → 1.0.2

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"));
@@ -514,7 +514,8 @@ function isTSESLintParserObject(value) {
514
514
  }
515
515
 
516
516
  // src/parser/script.ts
517
- var import_scope_manager = require("@typescript-eslint/scope-manager");
517
+ var import_types = require("@typescript-eslint/types");
518
+ var import_scope_manager2 = require("@typescript-eslint/scope-manager");
518
519
  var import_eslint_scope = require("eslint-scope");
519
520
 
520
521
  // src/traverse.ts
@@ -558,6 +559,299 @@ function traverseNodes(node, visitor) {
558
559
  traverse(node, null, visitor);
559
560
  }
560
561
 
562
+ // src/parser/scope/index.ts
563
+ var import_scope_manager = require("@typescript-eslint/scope-manager");
564
+
565
+ // src/util/index.ts
566
+ function sortedLastIndex(array, compare) {
567
+ let lower = 0;
568
+ let upper = array.length;
569
+ while (lower < upper) {
570
+ const mid = Math.floor(lower + (upper - lower) / 2);
571
+ const target = compare(array[mid]);
572
+ if (target < 0) {
573
+ lower = mid + 1;
574
+ } else if (target > 0) {
575
+ upper = mid;
576
+ } else {
577
+ return mid + 1;
578
+ }
579
+ }
580
+ return upper;
581
+ }
582
+ function addElementToSortedArray(array, element, compare) {
583
+ const index = sortedLastIndex(array, (target) => compare(target, element));
584
+ array.splice(index, 0, element);
585
+ }
586
+ function addElementsToSortedArray(array, elements, compare) {
587
+ if (!elements.length) {
588
+ return;
589
+ }
590
+ let last = elements[0];
591
+ let index = sortedLastIndex(array, (target) => compare(target, last));
592
+ for (const element of elements) {
593
+ if (compare(last, element) > 0) {
594
+ index = sortedLastIndex(array, (target) => compare(target, element));
595
+ }
596
+ let e = array[index];
597
+ while (e && compare(e, element) <= 0) {
598
+ e = array[++index];
599
+ }
600
+ array.splice(index, 0, element);
601
+ last = element;
602
+ }
603
+ }
604
+
605
+ // src/parser/scope/index.ts
606
+ var READ_FLAG = 1;
607
+ var WRITE_FLAG = 2;
608
+ var READ_WRITE_FLAG = 3;
609
+ var REFERENCE_TYPE_VALUE_FLAG = 1;
610
+ var REFERENCE_TYPE_TYPE_FLAG = 2;
611
+ function getProgramScope(scopeManager) {
612
+ const globalScope = scopeManager.globalScope;
613
+ return globalScope.childScopes.find((s) => s.type === "module") || globalScope;
614
+ }
615
+ function removeAllScopeAndVariableAndReference(target, info) {
616
+ const targetScopes = /* @__PURE__ */ new Set();
617
+ traverseNodes(target, {
618
+ visitorKeys: info.visitorKeys,
619
+ enterNode(node) {
620
+ const scope = info.scopeManager.acquire(node);
621
+ if (scope) {
622
+ targetScopes.add(scope);
623
+ return;
624
+ }
625
+ if (node.type === "Identifier") {
626
+ let scope2 = getInnermostScopeFromNode(info.scopeManager, node);
627
+ while (scope2 && scope2.block.type !== "Program" && target.range[0] <= scope2.block.range[0] && scope2.block.range[1] <= target.range[1]) {
628
+ scope2 = scope2.upper;
629
+ }
630
+ if (targetScopes.has(scope2)) {
631
+ return;
632
+ }
633
+ removeIdentifierVariable(node, scope2);
634
+ removeIdentifierReference(node, scope2);
635
+ }
636
+ },
637
+ leaveNode() {
638
+ }
639
+ });
640
+ for (const scope of targetScopes) {
641
+ removeScope(info.scopeManager, scope);
642
+ }
643
+ }
644
+ function addVirtualReference(node, variable, scope, status) {
645
+ const reference = new import_scope_manager.Reference(
646
+ node,
647
+ scope,
648
+ status.write && status.read ? READ_WRITE_FLAG : status.write ? WRITE_FLAG : READ_FLAG,
649
+ void 0,
650
+ // writeExpr
651
+ void 0,
652
+ // maybeImplicitGlobal
653
+ void 0,
654
+ // init
655
+ status.typeRef ? REFERENCE_TYPE_TYPE_FLAG : REFERENCE_TYPE_VALUE_FLAG
656
+ );
657
+ reference.astroVirtualReference = true;
658
+ addReference(variable.references, reference);
659
+ reference.resolved = variable;
660
+ if (status.forceUsed) {
661
+ variable.eslintUsed = true;
662
+ }
663
+ return reference;
664
+ }
665
+ function addGlobalVariable(reference, scopeManager) {
666
+ const globalScope = scopeManager.globalScope;
667
+ const name2 = reference.identifier.name;
668
+ let variable = globalScope.set.get(name2);
669
+ if (!variable) {
670
+ variable = new import_scope_manager.Variable(name2, globalScope);
671
+ globalScope.variables.push(variable);
672
+ globalScope.set.set(name2, variable);
673
+ }
674
+ reference.resolved = variable;
675
+ variable.references.push(reference);
676
+ return variable;
677
+ }
678
+ function removeReferenceFromThrough(reference, baseScope) {
679
+ const variable = reference.resolved;
680
+ const name2 = reference.identifier.name;
681
+ let scope = baseScope;
682
+ while (scope) {
683
+ for (const ref of [...scope.through]) {
684
+ if (reference === ref) {
685
+ scope.through.splice(scope.through.indexOf(ref), 1);
686
+ } else if (ref.identifier.name === name2) {
687
+ ref.resolved = variable;
688
+ if (!variable.references.includes(ref)) {
689
+ addReference(variable.references, ref);
690
+ }
691
+ scope.through.splice(scope.through.indexOf(ref), 1);
692
+ }
693
+ }
694
+ scope = scope.upper;
695
+ }
696
+ }
697
+ function removeScope(scopeManager, scope) {
698
+ for (const childScope of scope.childScopes) {
699
+ removeScope(scopeManager, childScope);
700
+ }
701
+ while (scope.references[0]) {
702
+ removeReference(scope.references[0], scope);
703
+ }
704
+ const upper = scope.upper;
705
+ if (upper) {
706
+ const index2 = upper.childScopes.indexOf(scope);
707
+ if (index2 >= 0) {
708
+ upper.childScopes.splice(index2, 1);
709
+ }
710
+ }
711
+ const index = scopeManager.scopes.indexOf(scope);
712
+ if (index >= 0) {
713
+ scopeManager.scopes.splice(index, 1);
714
+ }
715
+ }
716
+ function removeReference(reference, baseScope) {
717
+ if (reference.resolved) {
718
+ if (reference.resolved.defs.some((d) => d.name === reference.identifier)) {
719
+ const varIndex = baseScope.variables.indexOf(reference.resolved);
720
+ if (varIndex >= 0) {
721
+ baseScope.variables.splice(varIndex, 1);
722
+ }
723
+ const name2 = reference.identifier.name;
724
+ if (reference.resolved === baseScope.set.get(name2)) {
725
+ baseScope.set.delete(name2);
726
+ }
727
+ } else {
728
+ const refIndex = reference.resolved.references.indexOf(reference);
729
+ if (refIndex >= 0) {
730
+ reference.resolved.references.splice(refIndex, 1);
731
+ }
732
+ }
733
+ }
734
+ let scope = baseScope;
735
+ while (scope) {
736
+ const refIndex = scope.references.indexOf(reference);
737
+ if (refIndex >= 0) {
738
+ scope.references.splice(refIndex, 1);
739
+ }
740
+ const throughIndex = scope.through.indexOf(reference);
741
+ if (throughIndex >= 0) {
742
+ scope.through.splice(throughIndex, 1);
743
+ }
744
+ scope = scope.upper;
745
+ }
746
+ }
747
+ function removeIdentifierVariable(node, scope) {
748
+ for (let varIndex = 0; varIndex < scope.variables.length; varIndex++) {
749
+ const variable = scope.variables[varIndex];
750
+ const defIndex = variable.defs.findIndex((def) => def.name === node);
751
+ if (defIndex < 0) {
752
+ continue;
753
+ }
754
+ variable.defs.splice(defIndex, 1);
755
+ if (variable.defs.length === 0) {
756
+ referencesToThrough(variable.references, scope);
757
+ variable.references.forEach((r) => {
758
+ if (r.init)
759
+ r.init = false;
760
+ r.resolved = null;
761
+ });
762
+ scope.variables.splice(varIndex, 1);
763
+ const name2 = node.name;
764
+ if (variable === scope.set.get(name2)) {
765
+ scope.set.delete(name2);
766
+ }
767
+ } else {
768
+ const idIndex = variable.identifiers.indexOf(node);
769
+ if (idIndex >= 0) {
770
+ variable.identifiers.splice(idIndex, 1);
771
+ }
772
+ }
773
+ return;
774
+ }
775
+ }
776
+ function removeIdentifierReference(node, scope) {
777
+ const reference = scope.references.find((ref) => ref.identifier === node);
778
+ if (reference) {
779
+ removeReference(reference, scope);
780
+ return true;
781
+ }
782
+ const location = node.range[0];
783
+ const pendingScopes = [];
784
+ for (const childScope of scope.childScopes) {
785
+ const range = childScope.block.range;
786
+ if (range[0] <= location && location < range[1]) {
787
+ if (removeIdentifierReference(node, childScope)) {
788
+ return true;
789
+ }
790
+ } else {
791
+ pendingScopes.push(childScope);
792
+ }
793
+ }
794
+ for (const childScope of pendingScopes) {
795
+ if (removeIdentifierReference(node, childScope)) {
796
+ return true;
797
+ }
798
+ }
799
+ return false;
800
+ }
801
+ function getInnermostScopeFromNode(scopeManager, currentNode) {
802
+ return getInnermostScope(
803
+ getScopeFromNode(scopeManager, currentNode),
804
+ currentNode
805
+ );
806
+ }
807
+ function getScopeFromNode(scopeManager, currentNode) {
808
+ let node = currentNode;
809
+ for (; node; node = node.parent || null) {
810
+ const scope = scopeManager.acquire(node, false);
811
+ if (scope) {
812
+ if (scope.type === "function-expression-name") {
813
+ return scope.childScopes[0];
814
+ }
815
+ if (scope.type === "global" && node.type === "Program" && node.sourceType === "module") {
816
+ return scope.childScopes.find((s) => s.type === "module") || scope;
817
+ }
818
+ return scope;
819
+ }
820
+ }
821
+ const global = scopeManager.globalScope;
822
+ return global;
823
+ }
824
+ function getInnermostScope(initialScope, node) {
825
+ for (const childScope of initialScope.childScopes) {
826
+ const range = childScope.block.range;
827
+ if (range[0] <= node.range[0] && node.range[1] <= range[1]) {
828
+ return getInnermostScope(childScope, node);
829
+ }
830
+ }
831
+ return initialScope;
832
+ }
833
+ function referencesToThrough(references, baseScope) {
834
+ let scope = baseScope;
835
+ while (scope) {
836
+ addAllReferences(scope.through, references);
837
+ scope = scope.upper;
838
+ }
839
+ }
840
+ function addAllReferences(list, elements) {
841
+ addElementsToSortedArray(
842
+ list,
843
+ elements,
844
+ (a, b) => a.identifier.range[0] - b.identifier.range[0]
845
+ );
846
+ }
847
+ function addReference(list, reference) {
848
+ addElementToSortedArray(
849
+ list,
850
+ reference,
851
+ (a, b) => a.identifier.range[0] - b.identifier.range[0]
852
+ );
853
+ }
854
+
561
855
  // src/parser/script.ts
562
856
  function parseScript(code, ctx, parserOptionsCtx) {
563
857
  const result = parseScriptInternal(code, ctx, parserOptionsCtx);
@@ -569,7 +863,7 @@ function parseScript(code, ctx, parserOptionsCtx) {
569
863
  }
570
864
  function analyzeScope(result, parserOptions) {
571
865
  try {
572
- return (0, import_scope_manager.analyze)(result.ast, {
866
+ return (0, import_scope_manager2.analyze)(result.ast, {
573
867
  globalReturn: parserOptions.ecmaFeatures?.globalReturn,
574
868
  jsxPragma: parserOptions.jsxPragma,
575
869
  jsxFragmentName: parserOptions.jsxFragmentName,
@@ -579,7 +873,7 @@ function analyzeScope(result, parserOptions) {
579
873
  } catch {
580
874
  }
581
875
  const ecmaFeatures = parserOptions.ecmaFeatures || {};
582
- return (0, import_eslint_scope.analyze)(result.ast, {
876
+ return analyzeForEcmaScript(result.ast, {
583
877
  ignoreEval: true,
584
878
  nodejsScope: ecmaFeatures.globalReturn,
585
879
  impliedStrict: ecmaFeatures.impliedStrict,
@@ -616,6 +910,73 @@ ${code}`
616
910
  patchResult?.terminate();
617
911
  }
618
912
  }
913
+ var Referencer = class extends import_eslint_scope.Referencer {
914
+ JSXAttribute(node) {
915
+ this.visit(node.value);
916
+ }
917
+ JSXClosingElement() {
918
+ }
919
+ JSXFragment(node) {
920
+ this.visitChildren(node);
921
+ }
922
+ JSXIdentifier(node) {
923
+ const scope = this.currentScope();
924
+ const ref = new import_scope_manager2.Reference(
925
+ node,
926
+ scope,
927
+ READ_FLAG,
928
+ void 0,
929
+ void 0,
930
+ false,
931
+ REFERENCE_TYPE_VALUE_FLAG
932
+ );
933
+ scope.references.push(ref);
934
+ scope.__left.push(ref);
935
+ }
936
+ JSXMemberExpression(node) {
937
+ if (node.object.type !== import_types.AST_NODE_TYPES.JSXIdentifier) {
938
+ this.visit(node.object);
939
+ } else {
940
+ if (node.object.name !== "this") {
941
+ this.visit(node.object);
942
+ }
943
+ }
944
+ }
945
+ JSXOpeningElement(node) {
946
+ if (node.name.type === import_types.AST_NODE_TYPES.JSXIdentifier) {
947
+ if (node.name.name[0].toUpperCase() === node.name.name[0] || node.name.name === "this") {
948
+ this.visit(node.name);
949
+ }
950
+ } else {
951
+ this.visit(node.name);
952
+ }
953
+ for (const attr of node.attributes) {
954
+ this.visit(attr);
955
+ }
956
+ }
957
+ };
958
+ function analyzeForEcmaScript(tree, providedOptions) {
959
+ const options = Object.assign(
960
+ {
961
+ optimistic: false,
962
+ nodejsScope: false,
963
+ impliedStrict: false,
964
+ sourceType: "script",
965
+ // one of ['script', 'module', 'commonjs']
966
+ ecmaVersion: 5,
967
+ childVisitorKeys: null,
968
+ fallback: "iteration"
969
+ },
970
+ providedOptions
971
+ );
972
+ const scopeManager = new import_eslint_scope.ScopeManager(
973
+ // @ts-expect-error -- No typings
974
+ options
975
+ );
976
+ const referencer = new Referencer(options, scopeManager);
977
+ referencer.visit(tree);
978
+ return scopeManager;
979
+ }
619
980
 
620
981
  // src/parser/sort.ts
621
982
  function sort(tokens) {
@@ -628,7 +989,7 @@ function sort(tokens) {
628
989
  }
629
990
 
630
991
  // src/parser/process-template.ts
631
- var import_types = require("@typescript-eslint/types");
992
+ var import_types2 = require("@typescript-eslint/types");
632
993
 
633
994
  // src/astro/index.ts
634
995
  var import_decode = require("entities/lib/decode.js");
@@ -1272,7 +1633,7 @@ function processTemplate(ctx, resultTemplate) {
1272
1633
  script.appendVirtualScript("<>");
1273
1634
  fragmentOpened = true;
1274
1635
  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)) {
1636
+ 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
1637
  const index = result.ast.body.indexOf(scriptNode);
1277
1638
  const rootFragment = result.ast.body[index] = scriptNode.expression;
1278
1639
  delete rootFragment.closingFragment;
@@ -1310,7 +1671,7 @@ function processTemplate(ctx, resultTemplate) {
1310
1671
  (_scriptNode, { result }) => {
1311
1672
  for (let index = 0; index < result.ast.body.length; index++) {
1312
1673
  const st = result.ast.body[index];
1313
- if (st.type === import_types.AST_NODE_TYPES.EmptyStatement) {
1674
+ if (st.type === import_types2.AST_NODE_TYPES.EmptyStatement) {
1314
1675
  if (st.range[0] === scriptEnd && st.range[1] === scriptEnd) {
1315
1676
  result.ast.body.splice(index, 1);
1316
1677
  break;
@@ -1320,11 +1681,11 @@ function processTemplate(ctx, resultTemplate) {
1320
1681
  return true;
1321
1682
  }
1322
1683
  );
1323
- script.restoreContext.addToken(import_types.AST_TOKEN_TYPES.Punctuator, [
1684
+ script.restoreContext.addToken(import_types2.AST_TOKEN_TYPES.Punctuator, [
1324
1685
  node.position.start.offset,
1325
1686
  node.position.start.offset + 3
1326
1687
  ]);
1327
- script.restoreContext.addToken(import_types.AST_TOKEN_TYPES.Punctuator, [
1688
+ script.restoreContext.addToken(import_types2.AST_TOKEN_TYPES.Punctuator, [
1328
1689
  end - 3,
1329
1690
  end
1330
1691
  ]);
@@ -1342,7 +1703,7 @@ function processTemplate(ctx, resultTemplate) {
1342
1703
  script.appendOriginal(start2);
1343
1704
  script.appendVirtualScript("<>");
1344
1705
  script.restoreContext.addRestoreNodeProcess((scriptNode) => {
1345
- if (scriptNode.range[0] === start2 && scriptNode.type === import_types.AST_NODE_TYPES.JSXFragment) {
1706
+ if (scriptNode.range[0] === start2 && scriptNode.type === import_types2.AST_NODE_TYPES.JSXFragment) {
1346
1707
  delete scriptNode.openingFragment;
1347
1708
  delete scriptNode.closingFragment;
1348
1709
  const fragmentNode = scriptNode;
@@ -1384,7 +1745,7 @@ function processTemplate(ctx, resultTemplate) {
1384
1745
  script.appendVirtualScript('"');
1385
1746
  script.restoreContext.addRestoreNodeProcess(
1386
1747
  (scriptNode, context) => {
1387
- if (scriptNode.type === import_types.AST_NODE_TYPES.JSXAttribute && scriptNode.range[0] === attrStart) {
1748
+ if (scriptNode.type === import_types2.AST_NODE_TYPES.JSXAttribute && scriptNode.range[0] === attrStart) {
1388
1749
  const attrNode = scriptNode;
1389
1750
  if (attrNode.value?.type === "Literal" && typeof attrNode.value.value === "string") {
1390
1751
  const raw = ctx.code.slice(start2, end);
@@ -1403,7 +1764,7 @@ function processTemplate(ctx, resultTemplate) {
1403
1764
  const jsxName = /[\s"'[\]{}]/u.test(attr.name) ? generateUniqueId(attr.name) : attr.name;
1404
1765
  script.appendVirtualScript(`${jsxName}=`);
1405
1766
  script.restoreContext.addRestoreNodeProcess((scriptNode) => {
1406
- if (scriptNode.type === import_types.AST_NODE_TYPES.JSXAttribute && scriptNode.range[0] === start2) {
1767
+ if (scriptNode.type === import_types2.AST_NODE_TYPES.JSXAttribute && scriptNode.range[0] === start2) {
1407
1768
  const attrNode = scriptNode;
1408
1769
  attrNode.type = "AstroShorthandAttribute";
1409
1770
  const locs = ctx.getLocations(
@@ -1427,7 +1788,7 @@ function processTemplate(ctx, resultTemplate) {
1427
1788
  script.appendOriginal(end);
1428
1789
  script.appendVirtualScript("}");
1429
1790
  script.restoreContext.addRestoreNodeProcess((scriptNode) => {
1430
- if (scriptNode.type === import_types.AST_NODE_TYPES.JSXAttribute && scriptNode.range[0] === attrStart) {
1791
+ if (scriptNode.type === import_types2.AST_NODE_TYPES.JSXAttribute && scriptNode.range[0] === attrStart) {
1431
1792
  const attrNode = scriptNode;
1432
1793
  attrNode.type = "AstroTemplateLiteralAttribute";
1433
1794
  return true;
@@ -1449,7 +1810,7 @@ function processTemplate(ctx, resultTemplate) {
1449
1810
  script.appendOriginal(start2);
1450
1811
  script.skipOriginalOffset(text.value.length);
1451
1812
  script.restoreContext.addRestoreNodeProcess((scriptNode) => {
1452
- if (scriptNode.type === import_types.AST_NODE_TYPES.JSXElement && scriptNode.range[0] === styleNodeStart) {
1813
+ if (scriptNode.type === import_types2.AST_NODE_TYPES.JSXElement && scriptNode.range[0] === styleNodeStart) {
1453
1814
  const textNode = {
1454
1815
  type: "AstroRawText",
1455
1816
  value: text.value,
@@ -1462,7 +1823,7 @@ function processTemplate(ctx, resultTemplate) {
1462
1823
  }
1463
1824
  return false;
1464
1825
  });
1465
- script.restoreContext.addToken(import_types.AST_TOKEN_TYPES.JSXText, [
1826
+ script.restoreContext.addToken(import_types2.AST_TOKEN_TYPES.JSXText, [
1466
1827
  start2,
1467
1828
  start2 + text.value.length
1468
1829
  ]);
@@ -1481,7 +1842,7 @@ function processTemplate(ctx, resultTemplate) {
1481
1842
  script.skipOriginalOffset(length - 2);
1482
1843
  script.appendOriginal(end);
1483
1844
  script.restoreContext.addRestoreNodeProcess((scriptNode, context) => {
1484
- if (scriptNode.range[0] === start && scriptNode.type === import_types.AST_NODE_TYPES.JSXFragment) {
1845
+ if (scriptNode.range[0] === start && scriptNode.type === import_types2.AST_NODE_TYPES.JSXFragment) {
1485
1846
  delete scriptNode.children;
1486
1847
  delete scriptNode.openingFragment;
1487
1848
  delete scriptNode.closingFragment;
@@ -1516,7 +1877,7 @@ function processTemplate(ctx, resultTemplate) {
1516
1877
  script.skipOriginalOffset(length - 2);
1517
1878
  script.appendOriginal(end);
1518
1879
  script.restoreContext.addRestoreNodeProcess((scriptNode, context) => {
1519
- if (scriptNode.range[0] === start && scriptNode.type === import_types.AST_NODE_TYPES.JSXFragment) {
1880
+ if (scriptNode.range[0] === start && scriptNode.type === import_types2.AST_NODE_TYPES.JSXFragment) {
1520
1881
  delete scriptNode.children;
1521
1882
  delete scriptNode.openingFragment;
1522
1883
  delete scriptNode.closingFragment;
@@ -1557,7 +1918,7 @@ function processTemplate(ctx, resultTemplate) {
1557
1918
  script.restoreContext.addRestoreNodeProcess(
1558
1919
  (scriptNode, context) => {
1559
1920
  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) {
1921
+ if (scriptNode.range[0] === offset && scriptNode.type === import_types2.AST_NODE_TYPES.JSXClosingElement && parent2.type === import_types2.AST_NODE_TYPES.JSXElement) {
1561
1922
  parent2.closingElement = null;
1562
1923
  return true;
1563
1924
  }
@@ -1614,32 +1975,32 @@ function processTemplate(ctx, resultTemplate) {
1614
1975
  }
1615
1976
  if (colonOffset != null) {
1616
1977
  const punctuatorIndex = start + colonOffset;
1617
- script.restoreContext.addToken(import_types.AST_TOKEN_TYPES.JSXIdentifier, [
1978
+ script.restoreContext.addToken(import_types2.AST_TOKEN_TYPES.JSXIdentifier, [
1618
1979
  start,
1619
1980
  punctuatorIndex
1620
1981
  ]);
1621
- script.restoreContext.addToken(import_types.AST_TOKEN_TYPES.Punctuator, [
1982
+ script.restoreContext.addToken(import_types2.AST_TOKEN_TYPES.Punctuator, [
1622
1983
  punctuatorIndex,
1623
1984
  punctuatorIndex + 1
1624
1985
  ]);
1625
- script.restoreContext.addToken(import_types.AST_TOKEN_TYPES.JSXIdentifier, [
1986
+ script.restoreContext.addToken(import_types2.AST_TOKEN_TYPES.JSXIdentifier, [
1626
1987
  punctuatorIndex + 1,
1627
1988
  start + attr.name.length
1628
1989
  ]);
1629
1990
  } else {
1630
- script.restoreContext.addToken(import_types.AST_TOKEN_TYPES.JSXIdentifier, [
1991
+ script.restoreContext.addToken(import_types2.AST_TOKEN_TYPES.JSXIdentifier, [
1631
1992
  start,
1632
1993
  start + attr.name.length
1633
1994
  ]);
1634
1995
  }
1635
1996
  script.restoreContext.addRestoreNodeProcess((scriptNode, context) => {
1636
- if (scriptNode.type === import_types.AST_NODE_TYPES.JSXAttribute && scriptNode.range[0] === targetIndex) {
1997
+ if (scriptNode.type === import_types2.AST_NODE_TYPES.JSXAttribute && scriptNode.range[0] === targetIndex) {
1637
1998
  const baseNameNode = scriptNode.name;
1638
1999
  if (colonOffset != null) {
1639
2000
  const nameNode = baseNameNode;
1640
- nameNode.type = import_types.AST_NODE_TYPES.JSXNamespacedName;
2001
+ nameNode.type = import_types2.AST_NODE_TYPES.JSXNamespacedName;
1641
2002
  nameNode.namespace = {
1642
- type: import_types.AST_NODE_TYPES.JSXIdentifier,
2003
+ type: import_types2.AST_NODE_TYPES.JSXIdentifier,
1643
2004
  name: attr.name.slice(0, colonOffset),
1644
2005
  ...ctx.getLocations(
1645
2006
  baseNameNode.range[0],
@@ -1647,7 +2008,7 @@ function processTemplate(ctx, resultTemplate) {
1647
2008
  )
1648
2009
  };
1649
2010
  nameNode.name = {
1650
- type: import_types.AST_NODE_TYPES.JSXIdentifier,
2011
+ type: import_types2.AST_NODE_TYPES.JSXIdentifier,
1651
2012
  name: attr.name.slice(colonOffset + 1),
1652
2013
  ...ctx.getLocations(
1653
2014
  baseNameNode.range[0] + colonOffset + 1,
@@ -1658,7 +2019,7 @@ function processTemplate(ctx, resultTemplate) {
1658
2019
  nameNode.namespace.parent = nameNode;
1659
2020
  nameNode.name.parent = nameNode;
1660
2021
  } else {
1661
- if (baseNameNode.type === import_types.AST_NODE_TYPES.JSXIdentifier) {
2022
+ if (baseNameNode.type === import_types2.AST_NODE_TYPES.JSXIdentifier) {
1662
2023
  const nameNode = baseNameNode;
1663
2024
  nameNode.name = attr.name;
1664
2025
  scriptNode.name = nameNode;
@@ -1686,52 +2047,12 @@ function processTemplate(ctx, resultTemplate) {
1686
2047
  });
1687
2048
  }
1688
2049
  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];
2050
+ let candidate = `$_${base.replace(/\W/g, "_")}${uniqueIdSeq++}`;
2051
+ while (usedUniqueIds.has(candidate) || ctx.code.includes(candidate)) {
2052
+ candidate = `$_${base.replace(/\W/g, "_")}${uniqueIdSeq++}`;
1732
2053
  }
1733
- array.splice(index, 0, element);
1734
- last = element;
2054
+ usedUniqueIds.add(candidate);
2055
+ return candidate;
1735
2056
  }
1736
2057
  }
1737
2058
 
@@ -2363,257 +2684,6 @@ var ParserOptionsContext = class {
2363
2684
  }
2364
2685
  };
2365
2686
 
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
2687
  // src/parser/index.ts
2618
2688
  function parseForESLint(code, options) {
2619
2689
  const { result: resultTemplate, context: ctx } = parseTemplate(
@@ -2700,11 +2770,11 @@ function extractTokens(ast, ctx) {
2700
2770
  }
2701
2771
  if (isPunctuator(c)) {
2702
2772
  ast.ast.tokens.push(
2703
- ctx.buildToken(import_types2.AST_TOKEN_TYPES.Punctuator, [index, index + 1])
2773
+ ctx.buildToken(import_types3.AST_TOKEN_TYPES.Punctuator, [index, index + 1])
2704
2774
  );
2705
2775
  } else {
2706
2776
  ast.ast.tokens.push(
2707
- ctx.buildToken(import_types2.AST_TOKEN_TYPES.Identifier, [index, index + 1])
2777
+ ctx.buildToken(import_types3.AST_TOKEN_TYPES.Identifier, [index, index + 1])
2708
2778
  );
2709
2779
  }
2710
2780
  }
@@ -2748,7 +2818,7 @@ __export(meta_exports, {
2748
2818
 
2749
2819
  // package.json
2750
2820
  var name = "astro-eslint-parser";
2751
- var version = "1.0.1";
2821
+ var version = "1.0.2";
2752
2822
 
2753
2823
  // src/index.ts
2754
2824
  function parseForESLint2(code, options) {