astro-eslint-parser 1.0.0 → 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,21 +514,375 @@ function isTSESLintParserObject(value) {
514
514
  }
515
515
 
516
516
  // src/parser/script.ts
517
+ var import_types = require("@typescript-eslint/types");
518
+ var import_scope_manager2 = require("@typescript-eslint/scope-manager");
519
+ var import_eslint_scope = require("eslint-scope");
520
+
521
+ // src/traverse.ts
522
+ function fallbackKeysFilter(key) {
523
+ let value = null;
524
+ return key !== "comments" && key !== "leadingComments" && key !== "loc" && key !== "parent" && key !== "range" && key !== "tokens" && key !== "trailingComments" && (value = this[key]) !== null && typeof value === "object" && (typeof value.type === "string" || Array.isArray(value));
525
+ }
526
+ function getFallbackKeys(node) {
527
+ return Object.keys(node).filter(fallbackKeysFilter, node);
528
+ }
529
+ function getKeys(node, visitorKeys) {
530
+ const keys = (visitorKeys || KEYS)[node.type] || getFallbackKeys(node);
531
+ return keys.filter((key) => !getNodes(node, key).next().done);
532
+ }
533
+ function* getNodes(node, key) {
534
+ const child = node[key];
535
+ if (Array.isArray(child)) {
536
+ for (const c of child) {
537
+ if (isNode(c)) {
538
+ yield c;
539
+ }
540
+ }
541
+ } else if (isNode(child)) {
542
+ yield child;
543
+ }
544
+ }
545
+ function isNode(x) {
546
+ return x !== null && typeof x === "object" && typeof x.type === "string";
547
+ }
548
+ function traverse(node, parent, visitor) {
549
+ visitor.enterNode(node, parent);
550
+ const keys = getKeys(node, visitor.visitorKeys);
551
+ for (const key of keys) {
552
+ for (const child of getNodes(node, key)) {
553
+ traverse(child, node, visitor);
554
+ }
555
+ }
556
+ visitor.leaveNode(node, parent);
557
+ }
558
+ function traverseNodes(node, visitor) {
559
+ traverse(node, null, visitor);
560
+ }
561
+
562
+ // src/parser/scope/index.ts
517
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
+
855
+ // src/parser/script.ts
518
856
  function parseScript(code, ctx, parserOptionsCtx) {
519
857
  const result = parseScriptInternal(code, ctx, parserOptionsCtx);
520
858
  const parserOptions = parserOptionsCtx.parserOptions;
521
859
  if (!result.scopeManager && parserOptions.eslintScopeManager) {
522
- result.scopeManager = (0, import_scope_manager.analyze)(result.ast, {
523
- ecmaVersion: 1e8,
860
+ result.scopeManager = analyzeScope(result, parserOptions);
861
+ }
862
+ return result;
863
+ }
864
+ function analyzeScope(result, parserOptions) {
865
+ try {
866
+ return (0, import_scope_manager2.analyze)(result.ast, {
524
867
  globalReturn: parserOptions.ecmaFeatures?.globalReturn,
525
868
  jsxPragma: parserOptions.jsxPragma,
526
869
  jsxFragmentName: parserOptions.jsxFragmentName,
527
870
  lib: parserOptions.lib,
528
871
  sourceType: parserOptions.sourceType
529
872
  });
873
+ } catch {
530
874
  }
531
- return result;
875
+ const ecmaFeatures = parserOptions.ecmaFeatures || {};
876
+ return analyzeForEcmaScript(result.ast, {
877
+ ignoreEval: true,
878
+ nodejsScope: ecmaFeatures.globalReturn,
879
+ impliedStrict: ecmaFeatures.impliedStrict,
880
+ ecmaVersion: 1e8,
881
+ sourceType: parserOptions.sourceType === "commonjs" ? "script" : parserOptions.sourceType || "script",
882
+ // @ts-expect-error -- Type bug?
883
+ childVisitorKeys: result.visitorKeys || KEYS,
884
+ fallback: getKeys
885
+ });
532
886
  }
533
887
  function parseScriptInternal(code, _ctx, parserOptionsCtx) {
534
888
  const parser = parserOptionsCtx.getParser();
@@ -556,6 +910,73 @@ ${code}`
556
910
  patchResult?.terminate();
557
911
  }
558
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
+ }
559
980
 
560
981
  // src/parser/sort.ts
561
982
  function sort(tokens) {
@@ -568,7 +989,7 @@ function sort(tokens) {
568
989
  }
569
990
 
570
991
  // src/parser/process-template.ts
571
- var import_types = require("@typescript-eslint/types");
992
+ var import_types2 = require("@typescript-eslint/types");
572
993
 
573
994
  // src/astro/index.ts
574
995
  var import_decode = require("entities/lib/decode.js");
@@ -986,47 +1407,6 @@ function getSortedChildren(parent, code) {
986
1407
  return parent.children;
987
1408
  }
988
1409
 
989
- // src/traverse.ts
990
- function fallbackKeysFilter(key) {
991
- let value = null;
992
- return key !== "comments" && key !== "leadingComments" && key !== "loc" && key !== "parent" && key !== "range" && key !== "tokens" && key !== "trailingComments" && (value = this[key]) !== null && typeof value === "object" && (typeof value.type === "string" || Array.isArray(value));
993
- }
994
- function getFallbackKeys(node) {
995
- return Object.keys(node).filter(fallbackKeysFilter, node);
996
- }
997
- function getKeys(node, visitorKeys) {
998
- const keys = (visitorKeys || KEYS)[node.type] || getFallbackKeys(node);
999
- return keys.filter((key) => !getNodes(node, key).next().done);
1000
- }
1001
- function* getNodes(node, key) {
1002
- const child = node[key];
1003
- if (Array.isArray(child)) {
1004
- for (const c of child) {
1005
- if (isNode(c)) {
1006
- yield c;
1007
- }
1008
- }
1009
- } else if (isNode(child)) {
1010
- yield child;
1011
- }
1012
- }
1013
- function isNode(x) {
1014
- return x !== null && typeof x === "object" && typeof x.type === "string";
1015
- }
1016
- function traverse(node, parent, visitor) {
1017
- visitor.enterNode(node, parent);
1018
- const keys = getKeys(node, visitor.visitorKeys);
1019
- for (const key of keys) {
1020
- for (const child of getNodes(node, key)) {
1021
- traverse(child, node, visitor);
1022
- }
1023
- }
1024
- visitor.leaveNode(node, parent);
1025
- }
1026
- function traverseNodes(node, visitor) {
1027
- traverse(node, null, visitor);
1028
- }
1029
-
1030
1410
  // src/context/restore.ts
1031
1411
  var RestoreNodeProcessContext = class {
1032
1412
  constructor(result, nodeMap) {
@@ -1253,7 +1633,7 @@ function processTemplate(ctx, resultTemplate) {
1253
1633
  script.appendVirtualScript("<>");
1254
1634
  fragmentOpened = true;
1255
1635
  script.restoreContext.addRestoreNodeProcess((scriptNode, { result }) => {
1256
- 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)) {
1257
1637
  const index = result.ast.body.indexOf(scriptNode);
1258
1638
  const rootFragment = result.ast.body[index] = scriptNode.expression;
1259
1639
  delete rootFragment.closingFragment;
@@ -1291,7 +1671,7 @@ function processTemplate(ctx, resultTemplate) {
1291
1671
  (_scriptNode, { result }) => {
1292
1672
  for (let index = 0; index < result.ast.body.length; index++) {
1293
1673
  const st = result.ast.body[index];
1294
- if (st.type === import_types.AST_NODE_TYPES.EmptyStatement) {
1674
+ if (st.type === import_types2.AST_NODE_TYPES.EmptyStatement) {
1295
1675
  if (st.range[0] === scriptEnd && st.range[1] === scriptEnd) {
1296
1676
  result.ast.body.splice(index, 1);
1297
1677
  break;
@@ -1301,11 +1681,11 @@ function processTemplate(ctx, resultTemplate) {
1301
1681
  return true;
1302
1682
  }
1303
1683
  );
1304
- script.restoreContext.addToken(import_types.AST_TOKEN_TYPES.Punctuator, [
1684
+ script.restoreContext.addToken(import_types2.AST_TOKEN_TYPES.Punctuator, [
1305
1685
  node.position.start.offset,
1306
1686
  node.position.start.offset + 3
1307
1687
  ]);
1308
- script.restoreContext.addToken(import_types.AST_TOKEN_TYPES.Punctuator, [
1688
+ script.restoreContext.addToken(import_types2.AST_TOKEN_TYPES.Punctuator, [
1309
1689
  end - 3,
1310
1690
  end
1311
1691
  ]);
@@ -1323,7 +1703,7 @@ function processTemplate(ctx, resultTemplate) {
1323
1703
  script.appendOriginal(start2);
1324
1704
  script.appendVirtualScript("<>");
1325
1705
  script.restoreContext.addRestoreNodeProcess((scriptNode) => {
1326
- 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) {
1327
1707
  delete scriptNode.openingFragment;
1328
1708
  delete scriptNode.closingFragment;
1329
1709
  const fragmentNode = scriptNode;
@@ -1365,7 +1745,7 @@ function processTemplate(ctx, resultTemplate) {
1365
1745
  script.appendVirtualScript('"');
1366
1746
  script.restoreContext.addRestoreNodeProcess(
1367
1747
  (scriptNode, context) => {
1368
- 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) {
1369
1749
  const attrNode = scriptNode;
1370
1750
  if (attrNode.value?.type === "Literal" && typeof attrNode.value.value === "string") {
1371
1751
  const raw = ctx.code.slice(start2, end);
@@ -1384,7 +1764,7 @@ function processTemplate(ctx, resultTemplate) {
1384
1764
  const jsxName = /[\s"'[\]{}]/u.test(attr.name) ? generateUniqueId(attr.name) : attr.name;
1385
1765
  script.appendVirtualScript(`${jsxName}=`);
1386
1766
  script.restoreContext.addRestoreNodeProcess((scriptNode) => {
1387
- 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) {
1388
1768
  const attrNode = scriptNode;
1389
1769
  attrNode.type = "AstroShorthandAttribute";
1390
1770
  const locs = ctx.getLocations(
@@ -1408,7 +1788,7 @@ function processTemplate(ctx, resultTemplate) {
1408
1788
  script.appendOriginal(end);
1409
1789
  script.appendVirtualScript("}");
1410
1790
  script.restoreContext.addRestoreNodeProcess((scriptNode) => {
1411
- 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) {
1412
1792
  const attrNode = scriptNode;
1413
1793
  attrNode.type = "AstroTemplateLiteralAttribute";
1414
1794
  return true;
@@ -1430,7 +1810,7 @@ function processTemplate(ctx, resultTemplate) {
1430
1810
  script.appendOriginal(start2);
1431
1811
  script.skipOriginalOffset(text.value.length);
1432
1812
  script.restoreContext.addRestoreNodeProcess((scriptNode) => {
1433
- 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) {
1434
1814
  const textNode = {
1435
1815
  type: "AstroRawText",
1436
1816
  value: text.value,
@@ -1443,7 +1823,7 @@ function processTemplate(ctx, resultTemplate) {
1443
1823
  }
1444
1824
  return false;
1445
1825
  });
1446
- script.restoreContext.addToken(import_types.AST_TOKEN_TYPES.JSXText, [
1826
+ script.restoreContext.addToken(import_types2.AST_TOKEN_TYPES.JSXText, [
1447
1827
  start2,
1448
1828
  start2 + text.value.length
1449
1829
  ]);
@@ -1462,7 +1842,7 @@ function processTemplate(ctx, resultTemplate) {
1462
1842
  script.skipOriginalOffset(length - 2);
1463
1843
  script.appendOriginal(end);
1464
1844
  script.restoreContext.addRestoreNodeProcess((scriptNode, context) => {
1465
- 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) {
1466
1846
  delete scriptNode.children;
1467
1847
  delete scriptNode.openingFragment;
1468
1848
  delete scriptNode.closingFragment;
@@ -1497,7 +1877,7 @@ function processTemplate(ctx, resultTemplate) {
1497
1877
  script.skipOriginalOffset(length - 2);
1498
1878
  script.appendOriginal(end);
1499
1879
  script.restoreContext.addRestoreNodeProcess((scriptNode, context) => {
1500
- 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) {
1501
1881
  delete scriptNode.children;
1502
1882
  delete scriptNode.openingFragment;
1503
1883
  delete scriptNode.closingFragment;
@@ -1538,7 +1918,7 @@ function processTemplate(ctx, resultTemplate) {
1538
1918
  script.restoreContext.addRestoreNodeProcess(
1539
1919
  (scriptNode, context) => {
1540
1920
  const parent2 = context.getParent(scriptNode);
1541
- 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) {
1542
1922
  parent2.closingElement = null;
1543
1923
  return true;
1544
1924
  }
@@ -1595,32 +1975,32 @@ function processTemplate(ctx, resultTemplate) {
1595
1975
  }
1596
1976
  if (colonOffset != null) {
1597
1977
  const punctuatorIndex = start + colonOffset;
1598
- script.restoreContext.addToken(import_types.AST_TOKEN_TYPES.JSXIdentifier, [
1978
+ script.restoreContext.addToken(import_types2.AST_TOKEN_TYPES.JSXIdentifier, [
1599
1979
  start,
1600
1980
  punctuatorIndex
1601
1981
  ]);
1602
- script.restoreContext.addToken(import_types.AST_TOKEN_TYPES.Punctuator, [
1982
+ script.restoreContext.addToken(import_types2.AST_TOKEN_TYPES.Punctuator, [
1603
1983
  punctuatorIndex,
1604
1984
  punctuatorIndex + 1
1605
1985
  ]);
1606
- script.restoreContext.addToken(import_types.AST_TOKEN_TYPES.JSXIdentifier, [
1986
+ script.restoreContext.addToken(import_types2.AST_TOKEN_TYPES.JSXIdentifier, [
1607
1987
  punctuatorIndex + 1,
1608
1988
  start + attr.name.length
1609
1989
  ]);
1610
1990
  } else {
1611
- script.restoreContext.addToken(import_types.AST_TOKEN_TYPES.JSXIdentifier, [
1991
+ script.restoreContext.addToken(import_types2.AST_TOKEN_TYPES.JSXIdentifier, [
1612
1992
  start,
1613
1993
  start + attr.name.length
1614
1994
  ]);
1615
1995
  }
1616
1996
  script.restoreContext.addRestoreNodeProcess((scriptNode, context) => {
1617
- 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) {
1618
1998
  const baseNameNode = scriptNode.name;
1619
1999
  if (colonOffset != null) {
1620
2000
  const nameNode = baseNameNode;
1621
- nameNode.type = import_types.AST_NODE_TYPES.JSXNamespacedName;
2001
+ nameNode.type = import_types2.AST_NODE_TYPES.JSXNamespacedName;
1622
2002
  nameNode.namespace = {
1623
- type: import_types.AST_NODE_TYPES.JSXIdentifier,
2003
+ type: import_types2.AST_NODE_TYPES.JSXIdentifier,
1624
2004
  name: attr.name.slice(0, colonOffset),
1625
2005
  ...ctx.getLocations(
1626
2006
  baseNameNode.range[0],
@@ -1628,7 +2008,7 @@ function processTemplate(ctx, resultTemplate) {
1628
2008
  )
1629
2009
  };
1630
2010
  nameNode.name = {
1631
- type: import_types.AST_NODE_TYPES.JSXIdentifier,
2011
+ type: import_types2.AST_NODE_TYPES.JSXIdentifier,
1632
2012
  name: attr.name.slice(colonOffset + 1),
1633
2013
  ...ctx.getLocations(
1634
2014
  baseNameNode.range[0] + colonOffset + 1,
@@ -1639,7 +2019,7 @@ function processTemplate(ctx, resultTemplate) {
1639
2019
  nameNode.namespace.parent = nameNode;
1640
2020
  nameNode.name.parent = nameNode;
1641
2021
  } else {
1642
- if (baseNameNode.type === import_types.AST_NODE_TYPES.JSXIdentifier) {
2022
+ if (baseNameNode.type === import_types2.AST_NODE_TYPES.JSXIdentifier) {
1643
2023
  const nameNode = baseNameNode;
1644
2024
  nameNode.name = attr.name;
1645
2025
  scriptNode.name = nameNode;
@@ -1667,52 +2047,12 @@ function processTemplate(ctx, resultTemplate) {
1667
2047
  });
1668
2048
  }
1669
2049
  function generateUniqueId(base) {
1670
- let candidate = `$_${base.replace(/\W/g, "_")}${uniqueIdSeq++}`;
1671
- while (usedUniqueIds.has(candidate) || ctx.code.includes(candidate)) {
1672
- candidate = `$_${base.replace(/\W/g, "_")}${uniqueIdSeq++}`;
1673
- }
1674
- usedUniqueIds.add(candidate);
1675
- return candidate;
1676
- }
1677
- }
1678
-
1679
- // src/util/index.ts
1680
- function sortedLastIndex(array, compare) {
1681
- let lower = 0;
1682
- let upper = array.length;
1683
- while (lower < upper) {
1684
- const mid = Math.floor(lower + (upper - lower) / 2);
1685
- const target = compare(array[mid]);
1686
- if (target < 0) {
1687
- lower = mid + 1;
1688
- } else if (target > 0) {
1689
- upper = mid;
1690
- } else {
1691
- return mid + 1;
1692
- }
1693
- }
1694
- return upper;
1695
- }
1696
- function addElementToSortedArray(array, element, compare) {
1697
- const index = sortedLastIndex(array, (target) => compare(target, element));
1698
- array.splice(index, 0, element);
1699
- }
1700
- function addElementsToSortedArray(array, elements, compare) {
1701
- if (!elements.length) {
1702
- return;
1703
- }
1704
- let last = elements[0];
1705
- let index = sortedLastIndex(array, (target) => compare(target, last));
1706
- for (const element of elements) {
1707
- if (compare(last, element) > 0) {
1708
- index = sortedLastIndex(array, (target) => compare(target, element));
1709
- }
1710
- let e = array[index];
1711
- while (e && compare(e, element) <= 0) {
1712
- 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++}`;
1713
2053
  }
1714
- array.splice(index, 0, element);
1715
- last = element;
2054
+ usedUniqueIds.add(candidate);
2055
+ return candidate;
1716
2056
  }
1717
2057
  }
1718
2058
 
@@ -2344,257 +2684,6 @@ var ParserOptionsContext = class {
2344
2684
  }
2345
2685
  };
2346
2686
 
2347
- // src/parser/scope/index.ts
2348
- var import_scope_manager2 = require("@typescript-eslint/scope-manager");
2349
- var READ_FLAG = 1;
2350
- var WRITE_FLAG = 2;
2351
- var READ_WRITE_FLAG = 3;
2352
- var REFERENCE_TYPE_VALUE_FLAG = 1;
2353
- var REFERENCE_TYPE_TYPE_FLAG = 2;
2354
- function getProgramScope(scopeManager) {
2355
- const globalScope = scopeManager.globalScope;
2356
- return globalScope.childScopes.find((s) => s.type === "module") || globalScope;
2357
- }
2358
- function removeAllScopeAndVariableAndReference(target, info) {
2359
- const targetScopes = /* @__PURE__ */ new Set();
2360
- traverseNodes(target, {
2361
- visitorKeys: info.visitorKeys,
2362
- enterNode(node) {
2363
- const scope = info.scopeManager.acquire(node);
2364
- if (scope) {
2365
- targetScopes.add(scope);
2366
- return;
2367
- }
2368
- if (node.type === "Identifier") {
2369
- let scope2 = getInnermostScopeFromNode(info.scopeManager, node);
2370
- while (scope2 && scope2.block.type !== "Program" && target.range[0] <= scope2.block.range[0] && scope2.block.range[1] <= target.range[1]) {
2371
- scope2 = scope2.upper;
2372
- }
2373
- if (targetScopes.has(scope2)) {
2374
- return;
2375
- }
2376
- removeIdentifierVariable(node, scope2);
2377
- removeIdentifierReference(node, scope2);
2378
- }
2379
- },
2380
- leaveNode() {
2381
- }
2382
- });
2383
- for (const scope of targetScopes) {
2384
- removeScope(info.scopeManager, scope);
2385
- }
2386
- }
2387
- function addVirtualReference(node, variable, scope, status) {
2388
- const reference = new import_scope_manager2.Reference(
2389
- node,
2390
- scope,
2391
- status.write && status.read ? READ_WRITE_FLAG : status.write ? WRITE_FLAG : READ_FLAG,
2392
- void 0,
2393
- // writeExpr
2394
- void 0,
2395
- // maybeImplicitGlobal
2396
- void 0,
2397
- // init
2398
- status.typeRef ? REFERENCE_TYPE_TYPE_FLAG : REFERENCE_TYPE_VALUE_FLAG
2399
- );
2400
- reference.astroVirtualReference = true;
2401
- addReference(variable.references, reference);
2402
- reference.resolved = variable;
2403
- if (status.forceUsed) {
2404
- variable.eslintUsed = true;
2405
- }
2406
- return reference;
2407
- }
2408
- function addGlobalVariable(reference, scopeManager) {
2409
- const globalScope = scopeManager.globalScope;
2410
- const name2 = reference.identifier.name;
2411
- let variable = globalScope.set.get(name2);
2412
- if (!variable) {
2413
- variable = new import_scope_manager2.Variable(name2, globalScope);
2414
- globalScope.variables.push(variable);
2415
- globalScope.set.set(name2, variable);
2416
- }
2417
- reference.resolved = variable;
2418
- variable.references.push(reference);
2419
- return variable;
2420
- }
2421
- function removeReferenceFromThrough(reference, baseScope) {
2422
- const variable = reference.resolved;
2423
- const name2 = reference.identifier.name;
2424
- let scope = baseScope;
2425
- while (scope) {
2426
- for (const ref of [...scope.through]) {
2427
- if (reference === ref) {
2428
- scope.through.splice(scope.through.indexOf(ref), 1);
2429
- } else if (ref.identifier.name === name2) {
2430
- ref.resolved = variable;
2431
- if (!variable.references.includes(ref)) {
2432
- addReference(variable.references, ref);
2433
- }
2434
- scope.through.splice(scope.through.indexOf(ref), 1);
2435
- }
2436
- }
2437
- scope = scope.upper;
2438
- }
2439
- }
2440
- function removeScope(scopeManager, scope) {
2441
- for (const childScope of scope.childScopes) {
2442
- removeScope(scopeManager, childScope);
2443
- }
2444
- while (scope.references[0]) {
2445
- removeReference(scope.references[0], scope);
2446
- }
2447
- const upper = scope.upper;
2448
- if (upper) {
2449
- const index2 = upper.childScopes.indexOf(scope);
2450
- if (index2 >= 0) {
2451
- upper.childScopes.splice(index2, 1);
2452
- }
2453
- }
2454
- const index = scopeManager.scopes.indexOf(scope);
2455
- if (index >= 0) {
2456
- scopeManager.scopes.splice(index, 1);
2457
- }
2458
- }
2459
- function removeReference(reference, baseScope) {
2460
- if (reference.resolved) {
2461
- if (reference.resolved.defs.some((d) => d.name === reference.identifier)) {
2462
- const varIndex = baseScope.variables.indexOf(reference.resolved);
2463
- if (varIndex >= 0) {
2464
- baseScope.variables.splice(varIndex, 1);
2465
- }
2466
- const name2 = reference.identifier.name;
2467
- if (reference.resolved === baseScope.set.get(name2)) {
2468
- baseScope.set.delete(name2);
2469
- }
2470
- } else {
2471
- const refIndex = reference.resolved.references.indexOf(reference);
2472
- if (refIndex >= 0) {
2473
- reference.resolved.references.splice(refIndex, 1);
2474
- }
2475
- }
2476
- }
2477
- let scope = baseScope;
2478
- while (scope) {
2479
- const refIndex = scope.references.indexOf(reference);
2480
- if (refIndex >= 0) {
2481
- scope.references.splice(refIndex, 1);
2482
- }
2483
- const throughIndex = scope.through.indexOf(reference);
2484
- if (throughIndex >= 0) {
2485
- scope.through.splice(throughIndex, 1);
2486
- }
2487
- scope = scope.upper;
2488
- }
2489
- }
2490
- function removeIdentifierVariable(node, scope) {
2491
- for (let varIndex = 0; varIndex < scope.variables.length; varIndex++) {
2492
- const variable = scope.variables[varIndex];
2493
- const defIndex = variable.defs.findIndex((def) => def.name === node);
2494
- if (defIndex < 0) {
2495
- continue;
2496
- }
2497
- variable.defs.splice(defIndex, 1);
2498
- if (variable.defs.length === 0) {
2499
- referencesToThrough(variable.references, scope);
2500
- variable.references.forEach((r) => {
2501
- if (r.init)
2502
- r.init = false;
2503
- r.resolved = null;
2504
- });
2505
- scope.variables.splice(varIndex, 1);
2506
- const name2 = node.name;
2507
- if (variable === scope.set.get(name2)) {
2508
- scope.set.delete(name2);
2509
- }
2510
- } else {
2511
- const idIndex = variable.identifiers.indexOf(node);
2512
- if (idIndex >= 0) {
2513
- variable.identifiers.splice(idIndex, 1);
2514
- }
2515
- }
2516
- return;
2517
- }
2518
- }
2519
- function removeIdentifierReference(node, scope) {
2520
- const reference = scope.references.find((ref) => ref.identifier === node);
2521
- if (reference) {
2522
- removeReference(reference, scope);
2523
- return true;
2524
- }
2525
- const location = node.range[0];
2526
- const pendingScopes = [];
2527
- for (const childScope of scope.childScopes) {
2528
- const range = childScope.block.range;
2529
- if (range[0] <= location && location < range[1]) {
2530
- if (removeIdentifierReference(node, childScope)) {
2531
- return true;
2532
- }
2533
- } else {
2534
- pendingScopes.push(childScope);
2535
- }
2536
- }
2537
- for (const childScope of pendingScopes) {
2538
- if (removeIdentifierReference(node, childScope)) {
2539
- return true;
2540
- }
2541
- }
2542
- return false;
2543
- }
2544
- function getInnermostScopeFromNode(scopeManager, currentNode) {
2545
- return getInnermostScope(
2546
- getScopeFromNode(scopeManager, currentNode),
2547
- currentNode
2548
- );
2549
- }
2550
- function getScopeFromNode(scopeManager, currentNode) {
2551
- let node = currentNode;
2552
- for (; node; node = node.parent || null) {
2553
- const scope = scopeManager.acquire(node, false);
2554
- if (scope) {
2555
- if (scope.type === "function-expression-name") {
2556
- return scope.childScopes[0];
2557
- }
2558
- if (scope.type === "global" && node.type === "Program" && node.sourceType === "module") {
2559
- return scope.childScopes.find((s) => s.type === "module") || scope;
2560
- }
2561
- return scope;
2562
- }
2563
- }
2564
- const global = scopeManager.globalScope;
2565
- return global;
2566
- }
2567
- function getInnermostScope(initialScope, node) {
2568
- for (const childScope of initialScope.childScopes) {
2569
- const range = childScope.block.range;
2570
- if (range[0] <= node.range[0] && node.range[1] <= range[1]) {
2571
- return getInnermostScope(childScope, node);
2572
- }
2573
- }
2574
- return initialScope;
2575
- }
2576
- function referencesToThrough(references, baseScope) {
2577
- let scope = baseScope;
2578
- while (scope) {
2579
- addAllReferences(scope.through, references);
2580
- scope = scope.upper;
2581
- }
2582
- }
2583
- function addAllReferences(list, elements) {
2584
- addElementsToSortedArray(
2585
- list,
2586
- elements,
2587
- (a, b) => a.identifier.range[0] - b.identifier.range[0]
2588
- );
2589
- }
2590
- function addReference(list, reference) {
2591
- addElementToSortedArray(
2592
- list,
2593
- reference,
2594
- (a, b) => a.identifier.range[0] - b.identifier.range[0]
2595
- );
2596
- }
2597
-
2598
2687
  // src/parser/index.ts
2599
2688
  function parseForESLint(code, options) {
2600
2689
  const { result: resultTemplate, context: ctx } = parseTemplate(
@@ -2681,11 +2770,11 @@ function extractTokens(ast, ctx) {
2681
2770
  }
2682
2771
  if (isPunctuator(c)) {
2683
2772
  ast.ast.tokens.push(
2684
- ctx.buildToken(import_types2.AST_TOKEN_TYPES.Punctuator, [index, index + 1])
2773
+ ctx.buildToken(import_types3.AST_TOKEN_TYPES.Punctuator, [index, index + 1])
2685
2774
  );
2686
2775
  } else {
2687
2776
  ast.ast.tokens.push(
2688
- ctx.buildToken(import_types2.AST_TOKEN_TYPES.Identifier, [index, index + 1])
2777
+ ctx.buildToken(import_types3.AST_TOKEN_TYPES.Identifier, [index, index + 1])
2689
2778
  );
2690
2779
  }
2691
2780
  }
@@ -2729,7 +2818,7 @@ __export(meta_exports, {
2729
2818
 
2730
2819
  // package.json
2731
2820
  var name = "astro-eslint-parser";
2732
- var version = "1.0.0";
2821
+ var version = "1.0.2";
2733
2822
 
2734
2823
  // src/index.ts
2735
2824
  function parseForESLint2(code, options) {