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.d.mts +1 -1
- package/lib/index.d.ts +1 -1
- package/lib/index.js +456 -367
- package/lib/index.mjs +453 -358
- package/package.json +3 -2
package/lib/index.mjs
CHANGED
|
@@ -484,21 +484,384 @@ function isTSESLintParserObject(value) {
|
|
|
484
484
|
}
|
|
485
485
|
|
|
486
486
|
// src/parser/script.ts
|
|
487
|
-
import {
|
|
487
|
+
import { AST_NODE_TYPES } from "@typescript-eslint/types";
|
|
488
|
+
import {
|
|
489
|
+
analyze as analyzeForTypeScript,
|
|
490
|
+
Reference
|
|
491
|
+
} from "@typescript-eslint/scope-manager";
|
|
492
|
+
import {
|
|
493
|
+
Referencer as BaseReferencer,
|
|
494
|
+
ScopeManager
|
|
495
|
+
} from "eslint-scope";
|
|
496
|
+
|
|
497
|
+
// src/traverse.ts
|
|
498
|
+
function fallbackKeysFilter(key) {
|
|
499
|
+
let value = null;
|
|
500
|
+
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));
|
|
501
|
+
}
|
|
502
|
+
function getFallbackKeys(node) {
|
|
503
|
+
return Object.keys(node).filter(fallbackKeysFilter, node);
|
|
504
|
+
}
|
|
505
|
+
function getKeys(node, visitorKeys) {
|
|
506
|
+
const keys = (visitorKeys || KEYS)[node.type] || getFallbackKeys(node);
|
|
507
|
+
return keys.filter((key) => !getNodes(node, key).next().done);
|
|
508
|
+
}
|
|
509
|
+
function* getNodes(node, key) {
|
|
510
|
+
const child = node[key];
|
|
511
|
+
if (Array.isArray(child)) {
|
|
512
|
+
for (const c of child) {
|
|
513
|
+
if (isNode(c)) {
|
|
514
|
+
yield c;
|
|
515
|
+
}
|
|
516
|
+
}
|
|
517
|
+
} else if (isNode(child)) {
|
|
518
|
+
yield child;
|
|
519
|
+
}
|
|
520
|
+
}
|
|
521
|
+
function isNode(x) {
|
|
522
|
+
return x !== null && typeof x === "object" && typeof x.type === "string";
|
|
523
|
+
}
|
|
524
|
+
function traverse(node, parent, visitor) {
|
|
525
|
+
visitor.enterNode(node, parent);
|
|
526
|
+
const keys = getKeys(node, visitor.visitorKeys);
|
|
527
|
+
for (const key of keys) {
|
|
528
|
+
for (const child of getNodes(node, key)) {
|
|
529
|
+
traverse(child, node, visitor);
|
|
530
|
+
}
|
|
531
|
+
}
|
|
532
|
+
visitor.leaveNode(node, parent);
|
|
533
|
+
}
|
|
534
|
+
function traverseNodes(node, visitor) {
|
|
535
|
+
traverse(node, null, visitor);
|
|
536
|
+
}
|
|
537
|
+
|
|
538
|
+
// src/parser/scope/index.ts
|
|
539
|
+
import {
|
|
540
|
+
Reference as ReferenceClass,
|
|
541
|
+
Variable as VariableClass
|
|
542
|
+
} from "@typescript-eslint/scope-manager";
|
|
543
|
+
|
|
544
|
+
// src/util/index.ts
|
|
545
|
+
function sortedLastIndex(array, compare) {
|
|
546
|
+
let lower = 0;
|
|
547
|
+
let upper = array.length;
|
|
548
|
+
while (lower < upper) {
|
|
549
|
+
const mid = Math.floor(lower + (upper - lower) / 2);
|
|
550
|
+
const target = compare(array[mid]);
|
|
551
|
+
if (target < 0) {
|
|
552
|
+
lower = mid + 1;
|
|
553
|
+
} else if (target > 0) {
|
|
554
|
+
upper = mid;
|
|
555
|
+
} else {
|
|
556
|
+
return mid + 1;
|
|
557
|
+
}
|
|
558
|
+
}
|
|
559
|
+
return upper;
|
|
560
|
+
}
|
|
561
|
+
function addElementToSortedArray(array, element, compare) {
|
|
562
|
+
const index = sortedLastIndex(array, (target) => compare(target, element));
|
|
563
|
+
array.splice(index, 0, element);
|
|
564
|
+
}
|
|
565
|
+
function addElementsToSortedArray(array, elements, compare) {
|
|
566
|
+
if (!elements.length) {
|
|
567
|
+
return;
|
|
568
|
+
}
|
|
569
|
+
let last = elements[0];
|
|
570
|
+
let index = sortedLastIndex(array, (target) => compare(target, last));
|
|
571
|
+
for (const element of elements) {
|
|
572
|
+
if (compare(last, element) > 0) {
|
|
573
|
+
index = sortedLastIndex(array, (target) => compare(target, element));
|
|
574
|
+
}
|
|
575
|
+
let e = array[index];
|
|
576
|
+
while (e && compare(e, element) <= 0) {
|
|
577
|
+
e = array[++index];
|
|
578
|
+
}
|
|
579
|
+
array.splice(index, 0, element);
|
|
580
|
+
last = element;
|
|
581
|
+
}
|
|
582
|
+
}
|
|
583
|
+
|
|
584
|
+
// src/parser/scope/index.ts
|
|
585
|
+
var READ_FLAG = 1;
|
|
586
|
+
var WRITE_FLAG = 2;
|
|
587
|
+
var READ_WRITE_FLAG = 3;
|
|
588
|
+
var REFERENCE_TYPE_VALUE_FLAG = 1;
|
|
589
|
+
var REFERENCE_TYPE_TYPE_FLAG = 2;
|
|
590
|
+
function getProgramScope(scopeManager) {
|
|
591
|
+
const globalScope = scopeManager.globalScope;
|
|
592
|
+
return globalScope.childScopes.find((s) => s.type === "module") || globalScope;
|
|
593
|
+
}
|
|
594
|
+
function removeAllScopeAndVariableAndReference(target, info) {
|
|
595
|
+
const targetScopes = /* @__PURE__ */ new Set();
|
|
596
|
+
traverseNodes(target, {
|
|
597
|
+
visitorKeys: info.visitorKeys,
|
|
598
|
+
enterNode(node) {
|
|
599
|
+
const scope = info.scopeManager.acquire(node);
|
|
600
|
+
if (scope) {
|
|
601
|
+
targetScopes.add(scope);
|
|
602
|
+
return;
|
|
603
|
+
}
|
|
604
|
+
if (node.type === "Identifier") {
|
|
605
|
+
let scope2 = getInnermostScopeFromNode(info.scopeManager, node);
|
|
606
|
+
while (scope2 && scope2.block.type !== "Program" && target.range[0] <= scope2.block.range[0] && scope2.block.range[1] <= target.range[1]) {
|
|
607
|
+
scope2 = scope2.upper;
|
|
608
|
+
}
|
|
609
|
+
if (targetScopes.has(scope2)) {
|
|
610
|
+
return;
|
|
611
|
+
}
|
|
612
|
+
removeIdentifierVariable(node, scope2);
|
|
613
|
+
removeIdentifierReference(node, scope2);
|
|
614
|
+
}
|
|
615
|
+
},
|
|
616
|
+
leaveNode() {
|
|
617
|
+
}
|
|
618
|
+
});
|
|
619
|
+
for (const scope of targetScopes) {
|
|
620
|
+
removeScope(info.scopeManager, scope);
|
|
621
|
+
}
|
|
622
|
+
}
|
|
623
|
+
function addVirtualReference(node, variable, scope, status) {
|
|
624
|
+
const reference = new ReferenceClass(
|
|
625
|
+
node,
|
|
626
|
+
scope,
|
|
627
|
+
status.write && status.read ? READ_WRITE_FLAG : status.write ? WRITE_FLAG : READ_FLAG,
|
|
628
|
+
void 0,
|
|
629
|
+
// writeExpr
|
|
630
|
+
void 0,
|
|
631
|
+
// maybeImplicitGlobal
|
|
632
|
+
void 0,
|
|
633
|
+
// init
|
|
634
|
+
status.typeRef ? REFERENCE_TYPE_TYPE_FLAG : REFERENCE_TYPE_VALUE_FLAG
|
|
635
|
+
);
|
|
636
|
+
reference.astroVirtualReference = true;
|
|
637
|
+
addReference(variable.references, reference);
|
|
638
|
+
reference.resolved = variable;
|
|
639
|
+
if (status.forceUsed) {
|
|
640
|
+
variable.eslintUsed = true;
|
|
641
|
+
}
|
|
642
|
+
return reference;
|
|
643
|
+
}
|
|
644
|
+
function addGlobalVariable(reference, scopeManager) {
|
|
645
|
+
const globalScope = scopeManager.globalScope;
|
|
646
|
+
const name2 = reference.identifier.name;
|
|
647
|
+
let variable = globalScope.set.get(name2);
|
|
648
|
+
if (!variable) {
|
|
649
|
+
variable = new VariableClass(name2, globalScope);
|
|
650
|
+
globalScope.variables.push(variable);
|
|
651
|
+
globalScope.set.set(name2, variable);
|
|
652
|
+
}
|
|
653
|
+
reference.resolved = variable;
|
|
654
|
+
variable.references.push(reference);
|
|
655
|
+
return variable;
|
|
656
|
+
}
|
|
657
|
+
function removeReferenceFromThrough(reference, baseScope) {
|
|
658
|
+
const variable = reference.resolved;
|
|
659
|
+
const name2 = reference.identifier.name;
|
|
660
|
+
let scope = baseScope;
|
|
661
|
+
while (scope) {
|
|
662
|
+
for (const ref of [...scope.through]) {
|
|
663
|
+
if (reference === ref) {
|
|
664
|
+
scope.through.splice(scope.through.indexOf(ref), 1);
|
|
665
|
+
} else if (ref.identifier.name === name2) {
|
|
666
|
+
ref.resolved = variable;
|
|
667
|
+
if (!variable.references.includes(ref)) {
|
|
668
|
+
addReference(variable.references, ref);
|
|
669
|
+
}
|
|
670
|
+
scope.through.splice(scope.through.indexOf(ref), 1);
|
|
671
|
+
}
|
|
672
|
+
}
|
|
673
|
+
scope = scope.upper;
|
|
674
|
+
}
|
|
675
|
+
}
|
|
676
|
+
function removeScope(scopeManager, scope) {
|
|
677
|
+
for (const childScope of scope.childScopes) {
|
|
678
|
+
removeScope(scopeManager, childScope);
|
|
679
|
+
}
|
|
680
|
+
while (scope.references[0]) {
|
|
681
|
+
removeReference(scope.references[0], scope);
|
|
682
|
+
}
|
|
683
|
+
const upper = scope.upper;
|
|
684
|
+
if (upper) {
|
|
685
|
+
const index2 = upper.childScopes.indexOf(scope);
|
|
686
|
+
if (index2 >= 0) {
|
|
687
|
+
upper.childScopes.splice(index2, 1);
|
|
688
|
+
}
|
|
689
|
+
}
|
|
690
|
+
const index = scopeManager.scopes.indexOf(scope);
|
|
691
|
+
if (index >= 0) {
|
|
692
|
+
scopeManager.scopes.splice(index, 1);
|
|
693
|
+
}
|
|
694
|
+
}
|
|
695
|
+
function removeReference(reference, baseScope) {
|
|
696
|
+
if (reference.resolved) {
|
|
697
|
+
if (reference.resolved.defs.some((d) => d.name === reference.identifier)) {
|
|
698
|
+
const varIndex = baseScope.variables.indexOf(reference.resolved);
|
|
699
|
+
if (varIndex >= 0) {
|
|
700
|
+
baseScope.variables.splice(varIndex, 1);
|
|
701
|
+
}
|
|
702
|
+
const name2 = reference.identifier.name;
|
|
703
|
+
if (reference.resolved === baseScope.set.get(name2)) {
|
|
704
|
+
baseScope.set.delete(name2);
|
|
705
|
+
}
|
|
706
|
+
} else {
|
|
707
|
+
const refIndex = reference.resolved.references.indexOf(reference);
|
|
708
|
+
if (refIndex >= 0) {
|
|
709
|
+
reference.resolved.references.splice(refIndex, 1);
|
|
710
|
+
}
|
|
711
|
+
}
|
|
712
|
+
}
|
|
713
|
+
let scope = baseScope;
|
|
714
|
+
while (scope) {
|
|
715
|
+
const refIndex = scope.references.indexOf(reference);
|
|
716
|
+
if (refIndex >= 0) {
|
|
717
|
+
scope.references.splice(refIndex, 1);
|
|
718
|
+
}
|
|
719
|
+
const throughIndex = scope.through.indexOf(reference);
|
|
720
|
+
if (throughIndex >= 0) {
|
|
721
|
+
scope.through.splice(throughIndex, 1);
|
|
722
|
+
}
|
|
723
|
+
scope = scope.upper;
|
|
724
|
+
}
|
|
725
|
+
}
|
|
726
|
+
function removeIdentifierVariable(node, scope) {
|
|
727
|
+
for (let varIndex = 0; varIndex < scope.variables.length; varIndex++) {
|
|
728
|
+
const variable = scope.variables[varIndex];
|
|
729
|
+
const defIndex = variable.defs.findIndex((def) => def.name === node);
|
|
730
|
+
if (defIndex < 0) {
|
|
731
|
+
continue;
|
|
732
|
+
}
|
|
733
|
+
variable.defs.splice(defIndex, 1);
|
|
734
|
+
if (variable.defs.length === 0) {
|
|
735
|
+
referencesToThrough(variable.references, scope);
|
|
736
|
+
variable.references.forEach((r) => {
|
|
737
|
+
if (r.init)
|
|
738
|
+
r.init = false;
|
|
739
|
+
r.resolved = null;
|
|
740
|
+
});
|
|
741
|
+
scope.variables.splice(varIndex, 1);
|
|
742
|
+
const name2 = node.name;
|
|
743
|
+
if (variable === scope.set.get(name2)) {
|
|
744
|
+
scope.set.delete(name2);
|
|
745
|
+
}
|
|
746
|
+
} else {
|
|
747
|
+
const idIndex = variable.identifiers.indexOf(node);
|
|
748
|
+
if (idIndex >= 0) {
|
|
749
|
+
variable.identifiers.splice(idIndex, 1);
|
|
750
|
+
}
|
|
751
|
+
}
|
|
752
|
+
return;
|
|
753
|
+
}
|
|
754
|
+
}
|
|
755
|
+
function removeIdentifierReference(node, scope) {
|
|
756
|
+
const reference = scope.references.find((ref) => ref.identifier === node);
|
|
757
|
+
if (reference) {
|
|
758
|
+
removeReference(reference, scope);
|
|
759
|
+
return true;
|
|
760
|
+
}
|
|
761
|
+
const location = node.range[0];
|
|
762
|
+
const pendingScopes = [];
|
|
763
|
+
for (const childScope of scope.childScopes) {
|
|
764
|
+
const range = childScope.block.range;
|
|
765
|
+
if (range[0] <= location && location < range[1]) {
|
|
766
|
+
if (removeIdentifierReference(node, childScope)) {
|
|
767
|
+
return true;
|
|
768
|
+
}
|
|
769
|
+
} else {
|
|
770
|
+
pendingScopes.push(childScope);
|
|
771
|
+
}
|
|
772
|
+
}
|
|
773
|
+
for (const childScope of pendingScopes) {
|
|
774
|
+
if (removeIdentifierReference(node, childScope)) {
|
|
775
|
+
return true;
|
|
776
|
+
}
|
|
777
|
+
}
|
|
778
|
+
return false;
|
|
779
|
+
}
|
|
780
|
+
function getInnermostScopeFromNode(scopeManager, currentNode) {
|
|
781
|
+
return getInnermostScope(
|
|
782
|
+
getScopeFromNode(scopeManager, currentNode),
|
|
783
|
+
currentNode
|
|
784
|
+
);
|
|
785
|
+
}
|
|
786
|
+
function getScopeFromNode(scopeManager, currentNode) {
|
|
787
|
+
let node = currentNode;
|
|
788
|
+
for (; node; node = node.parent || null) {
|
|
789
|
+
const scope = scopeManager.acquire(node, false);
|
|
790
|
+
if (scope) {
|
|
791
|
+
if (scope.type === "function-expression-name") {
|
|
792
|
+
return scope.childScopes[0];
|
|
793
|
+
}
|
|
794
|
+
if (scope.type === "global" && node.type === "Program" && node.sourceType === "module") {
|
|
795
|
+
return scope.childScopes.find((s) => s.type === "module") || scope;
|
|
796
|
+
}
|
|
797
|
+
return scope;
|
|
798
|
+
}
|
|
799
|
+
}
|
|
800
|
+
const global = scopeManager.globalScope;
|
|
801
|
+
return global;
|
|
802
|
+
}
|
|
803
|
+
function getInnermostScope(initialScope, node) {
|
|
804
|
+
for (const childScope of initialScope.childScopes) {
|
|
805
|
+
const range = childScope.block.range;
|
|
806
|
+
if (range[0] <= node.range[0] && node.range[1] <= range[1]) {
|
|
807
|
+
return getInnermostScope(childScope, node);
|
|
808
|
+
}
|
|
809
|
+
}
|
|
810
|
+
return initialScope;
|
|
811
|
+
}
|
|
812
|
+
function referencesToThrough(references, baseScope) {
|
|
813
|
+
let scope = baseScope;
|
|
814
|
+
while (scope) {
|
|
815
|
+
addAllReferences(scope.through, references);
|
|
816
|
+
scope = scope.upper;
|
|
817
|
+
}
|
|
818
|
+
}
|
|
819
|
+
function addAllReferences(list, elements) {
|
|
820
|
+
addElementsToSortedArray(
|
|
821
|
+
list,
|
|
822
|
+
elements,
|
|
823
|
+
(a, b) => a.identifier.range[0] - b.identifier.range[0]
|
|
824
|
+
);
|
|
825
|
+
}
|
|
826
|
+
function addReference(list, reference) {
|
|
827
|
+
addElementToSortedArray(
|
|
828
|
+
list,
|
|
829
|
+
reference,
|
|
830
|
+
(a, b) => a.identifier.range[0] - b.identifier.range[0]
|
|
831
|
+
);
|
|
832
|
+
}
|
|
833
|
+
|
|
834
|
+
// src/parser/script.ts
|
|
488
835
|
function parseScript(code, ctx, parserOptionsCtx) {
|
|
489
836
|
const result = parseScriptInternal(code, ctx, parserOptionsCtx);
|
|
490
837
|
const parserOptions = parserOptionsCtx.parserOptions;
|
|
491
838
|
if (!result.scopeManager && parserOptions.eslintScopeManager) {
|
|
492
|
-
result.scopeManager =
|
|
493
|
-
|
|
839
|
+
result.scopeManager = analyzeScope(result, parserOptions);
|
|
840
|
+
}
|
|
841
|
+
return result;
|
|
842
|
+
}
|
|
843
|
+
function analyzeScope(result, parserOptions) {
|
|
844
|
+
try {
|
|
845
|
+
return analyzeForTypeScript(result.ast, {
|
|
494
846
|
globalReturn: parserOptions.ecmaFeatures?.globalReturn,
|
|
495
847
|
jsxPragma: parserOptions.jsxPragma,
|
|
496
848
|
jsxFragmentName: parserOptions.jsxFragmentName,
|
|
497
849
|
lib: parserOptions.lib,
|
|
498
850
|
sourceType: parserOptions.sourceType
|
|
499
851
|
});
|
|
852
|
+
} catch {
|
|
500
853
|
}
|
|
501
|
-
|
|
854
|
+
const ecmaFeatures = parserOptions.ecmaFeatures || {};
|
|
855
|
+
return analyzeForEcmaScript(result.ast, {
|
|
856
|
+
ignoreEval: true,
|
|
857
|
+
nodejsScope: ecmaFeatures.globalReturn,
|
|
858
|
+
impliedStrict: ecmaFeatures.impliedStrict,
|
|
859
|
+
ecmaVersion: 1e8,
|
|
860
|
+
sourceType: parserOptions.sourceType === "commonjs" ? "script" : parserOptions.sourceType || "script",
|
|
861
|
+
// @ts-expect-error -- Type bug?
|
|
862
|
+
childVisitorKeys: result.visitorKeys || KEYS,
|
|
863
|
+
fallback: getKeys
|
|
864
|
+
});
|
|
502
865
|
}
|
|
503
866
|
function parseScriptInternal(code, _ctx, parserOptionsCtx) {
|
|
504
867
|
const parser = parserOptionsCtx.getParser();
|
|
@@ -526,6 +889,73 @@ ${code}`
|
|
|
526
889
|
patchResult?.terminate();
|
|
527
890
|
}
|
|
528
891
|
}
|
|
892
|
+
var Referencer = class extends BaseReferencer {
|
|
893
|
+
JSXAttribute(node) {
|
|
894
|
+
this.visit(node.value);
|
|
895
|
+
}
|
|
896
|
+
JSXClosingElement() {
|
|
897
|
+
}
|
|
898
|
+
JSXFragment(node) {
|
|
899
|
+
this.visitChildren(node);
|
|
900
|
+
}
|
|
901
|
+
JSXIdentifier(node) {
|
|
902
|
+
const scope = this.currentScope();
|
|
903
|
+
const ref = new Reference(
|
|
904
|
+
node,
|
|
905
|
+
scope,
|
|
906
|
+
READ_FLAG,
|
|
907
|
+
void 0,
|
|
908
|
+
void 0,
|
|
909
|
+
false,
|
|
910
|
+
REFERENCE_TYPE_VALUE_FLAG
|
|
911
|
+
);
|
|
912
|
+
scope.references.push(ref);
|
|
913
|
+
scope.__left.push(ref);
|
|
914
|
+
}
|
|
915
|
+
JSXMemberExpression(node) {
|
|
916
|
+
if (node.object.type !== AST_NODE_TYPES.JSXIdentifier) {
|
|
917
|
+
this.visit(node.object);
|
|
918
|
+
} else {
|
|
919
|
+
if (node.object.name !== "this") {
|
|
920
|
+
this.visit(node.object);
|
|
921
|
+
}
|
|
922
|
+
}
|
|
923
|
+
}
|
|
924
|
+
JSXOpeningElement(node) {
|
|
925
|
+
if (node.name.type === AST_NODE_TYPES.JSXIdentifier) {
|
|
926
|
+
if (node.name.name[0].toUpperCase() === node.name.name[0] || node.name.name === "this") {
|
|
927
|
+
this.visit(node.name);
|
|
928
|
+
}
|
|
929
|
+
} else {
|
|
930
|
+
this.visit(node.name);
|
|
931
|
+
}
|
|
932
|
+
for (const attr of node.attributes) {
|
|
933
|
+
this.visit(attr);
|
|
934
|
+
}
|
|
935
|
+
}
|
|
936
|
+
};
|
|
937
|
+
function analyzeForEcmaScript(tree, providedOptions) {
|
|
938
|
+
const options = Object.assign(
|
|
939
|
+
{
|
|
940
|
+
optimistic: false,
|
|
941
|
+
nodejsScope: false,
|
|
942
|
+
impliedStrict: false,
|
|
943
|
+
sourceType: "script",
|
|
944
|
+
// one of ['script', 'module', 'commonjs']
|
|
945
|
+
ecmaVersion: 5,
|
|
946
|
+
childVisitorKeys: null,
|
|
947
|
+
fallback: "iteration"
|
|
948
|
+
},
|
|
949
|
+
providedOptions
|
|
950
|
+
);
|
|
951
|
+
const scopeManager = new ScopeManager(
|
|
952
|
+
// @ts-expect-error -- No typings
|
|
953
|
+
options
|
|
954
|
+
);
|
|
955
|
+
const referencer = new Referencer(options, scopeManager);
|
|
956
|
+
referencer.visit(tree);
|
|
957
|
+
return scopeManager;
|
|
958
|
+
}
|
|
529
959
|
|
|
530
960
|
// src/parser/sort.ts
|
|
531
961
|
function sort(tokens) {
|
|
@@ -538,7 +968,7 @@ function sort(tokens) {
|
|
|
538
968
|
}
|
|
539
969
|
|
|
540
970
|
// src/parser/process-template.ts
|
|
541
|
-
import { AST_TOKEN_TYPES, AST_NODE_TYPES } from "@typescript-eslint/types";
|
|
971
|
+
import { AST_TOKEN_TYPES, AST_NODE_TYPES as AST_NODE_TYPES2 } from "@typescript-eslint/types";
|
|
542
972
|
|
|
543
973
|
// src/astro/index.ts
|
|
544
974
|
import {
|
|
@@ -960,47 +1390,6 @@ function getSortedChildren(parent, code) {
|
|
|
960
1390
|
return parent.children;
|
|
961
1391
|
}
|
|
962
1392
|
|
|
963
|
-
// src/traverse.ts
|
|
964
|
-
function fallbackKeysFilter(key) {
|
|
965
|
-
let value = null;
|
|
966
|
-
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));
|
|
967
|
-
}
|
|
968
|
-
function getFallbackKeys(node) {
|
|
969
|
-
return Object.keys(node).filter(fallbackKeysFilter, node);
|
|
970
|
-
}
|
|
971
|
-
function getKeys(node, visitorKeys) {
|
|
972
|
-
const keys = (visitorKeys || KEYS)[node.type] || getFallbackKeys(node);
|
|
973
|
-
return keys.filter((key) => !getNodes(node, key).next().done);
|
|
974
|
-
}
|
|
975
|
-
function* getNodes(node, key) {
|
|
976
|
-
const child = node[key];
|
|
977
|
-
if (Array.isArray(child)) {
|
|
978
|
-
for (const c of child) {
|
|
979
|
-
if (isNode(c)) {
|
|
980
|
-
yield c;
|
|
981
|
-
}
|
|
982
|
-
}
|
|
983
|
-
} else if (isNode(child)) {
|
|
984
|
-
yield child;
|
|
985
|
-
}
|
|
986
|
-
}
|
|
987
|
-
function isNode(x) {
|
|
988
|
-
return x !== null && typeof x === "object" && typeof x.type === "string";
|
|
989
|
-
}
|
|
990
|
-
function traverse(node, parent, visitor) {
|
|
991
|
-
visitor.enterNode(node, parent);
|
|
992
|
-
const keys = getKeys(node, visitor.visitorKeys);
|
|
993
|
-
for (const key of keys) {
|
|
994
|
-
for (const child of getNodes(node, key)) {
|
|
995
|
-
traverse(child, node, visitor);
|
|
996
|
-
}
|
|
997
|
-
}
|
|
998
|
-
visitor.leaveNode(node, parent);
|
|
999
|
-
}
|
|
1000
|
-
function traverseNodes(node, visitor) {
|
|
1001
|
-
traverse(node, null, visitor);
|
|
1002
|
-
}
|
|
1003
|
-
|
|
1004
1393
|
// src/context/restore.ts
|
|
1005
1394
|
var RestoreNodeProcessContext = class {
|
|
1006
1395
|
constructor(result, nodeMap) {
|
|
@@ -1227,7 +1616,7 @@ function processTemplate(ctx, resultTemplate) {
|
|
|
1227
1616
|
script.appendVirtualScript("<>");
|
|
1228
1617
|
fragmentOpened = true;
|
|
1229
1618
|
script.restoreContext.addRestoreNodeProcess((scriptNode, { result }) => {
|
|
1230
|
-
if (scriptNode.type ===
|
|
1619
|
+
if (scriptNode.type === AST_NODE_TYPES2.ExpressionStatement && scriptNode.expression.type === AST_NODE_TYPES2.JSXFragment && scriptNode.range[0] === startOffset && result.ast.body.includes(scriptNode)) {
|
|
1231
1620
|
const index = result.ast.body.indexOf(scriptNode);
|
|
1232
1621
|
const rootFragment = result.ast.body[index] = scriptNode.expression;
|
|
1233
1622
|
delete rootFragment.closingFragment;
|
|
@@ -1265,7 +1654,7 @@ function processTemplate(ctx, resultTemplate) {
|
|
|
1265
1654
|
(_scriptNode, { result }) => {
|
|
1266
1655
|
for (let index = 0; index < result.ast.body.length; index++) {
|
|
1267
1656
|
const st = result.ast.body[index];
|
|
1268
|
-
if (st.type ===
|
|
1657
|
+
if (st.type === AST_NODE_TYPES2.EmptyStatement) {
|
|
1269
1658
|
if (st.range[0] === scriptEnd && st.range[1] === scriptEnd) {
|
|
1270
1659
|
result.ast.body.splice(index, 1);
|
|
1271
1660
|
break;
|
|
@@ -1297,7 +1686,7 @@ function processTemplate(ctx, resultTemplate) {
|
|
|
1297
1686
|
script.appendOriginal(start2);
|
|
1298
1687
|
script.appendVirtualScript("<>");
|
|
1299
1688
|
script.restoreContext.addRestoreNodeProcess((scriptNode) => {
|
|
1300
|
-
if (scriptNode.range[0] === start2 && scriptNode.type ===
|
|
1689
|
+
if (scriptNode.range[0] === start2 && scriptNode.type === AST_NODE_TYPES2.JSXFragment) {
|
|
1301
1690
|
delete scriptNode.openingFragment;
|
|
1302
1691
|
delete scriptNode.closingFragment;
|
|
1303
1692
|
const fragmentNode = scriptNode;
|
|
@@ -1339,7 +1728,7 @@ function processTemplate(ctx, resultTemplate) {
|
|
|
1339
1728
|
script.appendVirtualScript('"');
|
|
1340
1729
|
script.restoreContext.addRestoreNodeProcess(
|
|
1341
1730
|
(scriptNode, context) => {
|
|
1342
|
-
if (scriptNode.type ===
|
|
1731
|
+
if (scriptNode.type === AST_NODE_TYPES2.JSXAttribute && scriptNode.range[0] === attrStart) {
|
|
1343
1732
|
const attrNode = scriptNode;
|
|
1344
1733
|
if (attrNode.value?.type === "Literal" && typeof attrNode.value.value === "string") {
|
|
1345
1734
|
const raw = ctx.code.slice(start2, end);
|
|
@@ -1358,7 +1747,7 @@ function processTemplate(ctx, resultTemplate) {
|
|
|
1358
1747
|
const jsxName = /[\s"'[\]{}]/u.test(attr.name) ? generateUniqueId(attr.name) : attr.name;
|
|
1359
1748
|
script.appendVirtualScript(`${jsxName}=`);
|
|
1360
1749
|
script.restoreContext.addRestoreNodeProcess((scriptNode) => {
|
|
1361
|
-
if (scriptNode.type ===
|
|
1750
|
+
if (scriptNode.type === AST_NODE_TYPES2.JSXAttribute && scriptNode.range[0] === start2) {
|
|
1362
1751
|
const attrNode = scriptNode;
|
|
1363
1752
|
attrNode.type = "AstroShorthandAttribute";
|
|
1364
1753
|
const locs = ctx.getLocations(
|
|
@@ -1382,7 +1771,7 @@ function processTemplate(ctx, resultTemplate) {
|
|
|
1382
1771
|
script.appendOriginal(end);
|
|
1383
1772
|
script.appendVirtualScript("}");
|
|
1384
1773
|
script.restoreContext.addRestoreNodeProcess((scriptNode) => {
|
|
1385
|
-
if (scriptNode.type ===
|
|
1774
|
+
if (scriptNode.type === AST_NODE_TYPES2.JSXAttribute && scriptNode.range[0] === attrStart) {
|
|
1386
1775
|
const attrNode = scriptNode;
|
|
1387
1776
|
attrNode.type = "AstroTemplateLiteralAttribute";
|
|
1388
1777
|
return true;
|
|
@@ -1404,7 +1793,7 @@ function processTemplate(ctx, resultTemplate) {
|
|
|
1404
1793
|
script.appendOriginal(start2);
|
|
1405
1794
|
script.skipOriginalOffset(text.value.length);
|
|
1406
1795
|
script.restoreContext.addRestoreNodeProcess((scriptNode) => {
|
|
1407
|
-
if (scriptNode.type ===
|
|
1796
|
+
if (scriptNode.type === AST_NODE_TYPES2.JSXElement && scriptNode.range[0] === styleNodeStart) {
|
|
1408
1797
|
const textNode = {
|
|
1409
1798
|
type: "AstroRawText",
|
|
1410
1799
|
value: text.value,
|
|
@@ -1436,7 +1825,7 @@ function processTemplate(ctx, resultTemplate) {
|
|
|
1436
1825
|
script.skipOriginalOffset(length - 2);
|
|
1437
1826
|
script.appendOriginal(end);
|
|
1438
1827
|
script.restoreContext.addRestoreNodeProcess((scriptNode, context) => {
|
|
1439
|
-
if (scriptNode.range[0] === start && scriptNode.type ===
|
|
1828
|
+
if (scriptNode.range[0] === start && scriptNode.type === AST_NODE_TYPES2.JSXFragment) {
|
|
1440
1829
|
delete scriptNode.children;
|
|
1441
1830
|
delete scriptNode.openingFragment;
|
|
1442
1831
|
delete scriptNode.closingFragment;
|
|
@@ -1471,7 +1860,7 @@ function processTemplate(ctx, resultTemplate) {
|
|
|
1471
1860
|
script.skipOriginalOffset(length - 2);
|
|
1472
1861
|
script.appendOriginal(end);
|
|
1473
1862
|
script.restoreContext.addRestoreNodeProcess((scriptNode, context) => {
|
|
1474
|
-
if (scriptNode.range[0] === start && scriptNode.type ===
|
|
1863
|
+
if (scriptNode.range[0] === start && scriptNode.type === AST_NODE_TYPES2.JSXFragment) {
|
|
1475
1864
|
delete scriptNode.children;
|
|
1476
1865
|
delete scriptNode.openingFragment;
|
|
1477
1866
|
delete scriptNode.closingFragment;
|
|
@@ -1512,7 +1901,7 @@ function processTemplate(ctx, resultTemplate) {
|
|
|
1512
1901
|
script.restoreContext.addRestoreNodeProcess(
|
|
1513
1902
|
(scriptNode, context) => {
|
|
1514
1903
|
const parent2 = context.getParent(scriptNode);
|
|
1515
|
-
if (scriptNode.range[0] === offset && scriptNode.type ===
|
|
1904
|
+
if (scriptNode.range[0] === offset && scriptNode.type === AST_NODE_TYPES2.JSXClosingElement && parent2.type === AST_NODE_TYPES2.JSXElement) {
|
|
1516
1905
|
parent2.closingElement = null;
|
|
1517
1906
|
return true;
|
|
1518
1907
|
}
|
|
@@ -1588,13 +1977,13 @@ function processTemplate(ctx, resultTemplate) {
|
|
|
1588
1977
|
]);
|
|
1589
1978
|
}
|
|
1590
1979
|
script.restoreContext.addRestoreNodeProcess((scriptNode, context) => {
|
|
1591
|
-
if (scriptNode.type ===
|
|
1980
|
+
if (scriptNode.type === AST_NODE_TYPES2.JSXAttribute && scriptNode.range[0] === targetIndex) {
|
|
1592
1981
|
const baseNameNode = scriptNode.name;
|
|
1593
1982
|
if (colonOffset != null) {
|
|
1594
1983
|
const nameNode = baseNameNode;
|
|
1595
|
-
nameNode.type =
|
|
1984
|
+
nameNode.type = AST_NODE_TYPES2.JSXNamespacedName;
|
|
1596
1985
|
nameNode.namespace = {
|
|
1597
|
-
type:
|
|
1986
|
+
type: AST_NODE_TYPES2.JSXIdentifier,
|
|
1598
1987
|
name: attr.name.slice(0, colonOffset),
|
|
1599
1988
|
...ctx.getLocations(
|
|
1600
1989
|
baseNameNode.range[0],
|
|
@@ -1602,7 +1991,7 @@ function processTemplate(ctx, resultTemplate) {
|
|
|
1602
1991
|
)
|
|
1603
1992
|
};
|
|
1604
1993
|
nameNode.name = {
|
|
1605
|
-
type:
|
|
1994
|
+
type: AST_NODE_TYPES2.JSXIdentifier,
|
|
1606
1995
|
name: attr.name.slice(colonOffset + 1),
|
|
1607
1996
|
...ctx.getLocations(
|
|
1608
1997
|
baseNameNode.range[0] + colonOffset + 1,
|
|
@@ -1613,7 +2002,7 @@ function processTemplate(ctx, resultTemplate) {
|
|
|
1613
2002
|
nameNode.namespace.parent = nameNode;
|
|
1614
2003
|
nameNode.name.parent = nameNode;
|
|
1615
2004
|
} else {
|
|
1616
|
-
if (baseNameNode.type ===
|
|
2005
|
+
if (baseNameNode.type === AST_NODE_TYPES2.JSXIdentifier) {
|
|
1617
2006
|
const nameNode = baseNameNode;
|
|
1618
2007
|
nameNode.name = attr.name;
|
|
1619
2008
|
scriptNode.name = nameNode;
|
|
@@ -1645,48 +2034,8 @@ function processTemplate(ctx, resultTemplate) {
|
|
|
1645
2034
|
while (usedUniqueIds.has(candidate) || ctx.code.includes(candidate)) {
|
|
1646
2035
|
candidate = `$_${base.replace(/\W/g, "_")}${uniqueIdSeq++}`;
|
|
1647
2036
|
}
|
|
1648
|
-
usedUniqueIds.add(candidate);
|
|
1649
|
-
return candidate;
|
|
1650
|
-
}
|
|
1651
|
-
}
|
|
1652
|
-
|
|
1653
|
-
// src/util/index.ts
|
|
1654
|
-
function sortedLastIndex(array, compare) {
|
|
1655
|
-
let lower = 0;
|
|
1656
|
-
let upper = array.length;
|
|
1657
|
-
while (lower < upper) {
|
|
1658
|
-
const mid = Math.floor(lower + (upper - lower) / 2);
|
|
1659
|
-
const target = compare(array[mid]);
|
|
1660
|
-
if (target < 0) {
|
|
1661
|
-
lower = mid + 1;
|
|
1662
|
-
} else if (target > 0) {
|
|
1663
|
-
upper = mid;
|
|
1664
|
-
} else {
|
|
1665
|
-
return mid + 1;
|
|
1666
|
-
}
|
|
1667
|
-
}
|
|
1668
|
-
return upper;
|
|
1669
|
-
}
|
|
1670
|
-
function addElementToSortedArray(array, element, compare) {
|
|
1671
|
-
const index = sortedLastIndex(array, (target) => compare(target, element));
|
|
1672
|
-
array.splice(index, 0, element);
|
|
1673
|
-
}
|
|
1674
|
-
function addElementsToSortedArray(array, elements, compare) {
|
|
1675
|
-
if (!elements.length) {
|
|
1676
|
-
return;
|
|
1677
|
-
}
|
|
1678
|
-
let last = elements[0];
|
|
1679
|
-
let index = sortedLastIndex(array, (target) => compare(target, last));
|
|
1680
|
-
for (const element of elements) {
|
|
1681
|
-
if (compare(last, element) > 0) {
|
|
1682
|
-
index = sortedLastIndex(array, (target) => compare(target, element));
|
|
1683
|
-
}
|
|
1684
|
-
let e = array[index];
|
|
1685
|
-
while (e && compare(e, element) <= 0) {
|
|
1686
|
-
e = array[++index];
|
|
1687
|
-
}
|
|
1688
|
-
array.splice(index, 0, element);
|
|
1689
|
-
last = element;
|
|
2037
|
+
usedUniqueIds.add(candidate);
|
|
2038
|
+
return candidate;
|
|
1690
2039
|
}
|
|
1691
2040
|
}
|
|
1692
2041
|
|
|
@@ -2318,260 +2667,6 @@ var ParserOptionsContext = class {
|
|
|
2318
2667
|
}
|
|
2319
2668
|
};
|
|
2320
2669
|
|
|
2321
|
-
// src/parser/scope/index.ts
|
|
2322
|
-
import {
|
|
2323
|
-
Reference as ReferenceClass,
|
|
2324
|
-
Variable as VariableClass
|
|
2325
|
-
} from "@typescript-eslint/scope-manager";
|
|
2326
|
-
var READ_FLAG = 1;
|
|
2327
|
-
var WRITE_FLAG = 2;
|
|
2328
|
-
var READ_WRITE_FLAG = 3;
|
|
2329
|
-
var REFERENCE_TYPE_VALUE_FLAG = 1;
|
|
2330
|
-
var REFERENCE_TYPE_TYPE_FLAG = 2;
|
|
2331
|
-
function getProgramScope(scopeManager) {
|
|
2332
|
-
const globalScope = scopeManager.globalScope;
|
|
2333
|
-
return globalScope.childScopes.find((s) => s.type === "module") || globalScope;
|
|
2334
|
-
}
|
|
2335
|
-
function removeAllScopeAndVariableAndReference(target, info) {
|
|
2336
|
-
const targetScopes = /* @__PURE__ */ new Set();
|
|
2337
|
-
traverseNodes(target, {
|
|
2338
|
-
visitorKeys: info.visitorKeys,
|
|
2339
|
-
enterNode(node) {
|
|
2340
|
-
const scope = info.scopeManager.acquire(node);
|
|
2341
|
-
if (scope) {
|
|
2342
|
-
targetScopes.add(scope);
|
|
2343
|
-
return;
|
|
2344
|
-
}
|
|
2345
|
-
if (node.type === "Identifier") {
|
|
2346
|
-
let scope2 = getInnermostScopeFromNode(info.scopeManager, node);
|
|
2347
|
-
while (scope2 && scope2.block.type !== "Program" && target.range[0] <= scope2.block.range[0] && scope2.block.range[1] <= target.range[1]) {
|
|
2348
|
-
scope2 = scope2.upper;
|
|
2349
|
-
}
|
|
2350
|
-
if (targetScopes.has(scope2)) {
|
|
2351
|
-
return;
|
|
2352
|
-
}
|
|
2353
|
-
removeIdentifierVariable(node, scope2);
|
|
2354
|
-
removeIdentifierReference(node, scope2);
|
|
2355
|
-
}
|
|
2356
|
-
},
|
|
2357
|
-
leaveNode() {
|
|
2358
|
-
}
|
|
2359
|
-
});
|
|
2360
|
-
for (const scope of targetScopes) {
|
|
2361
|
-
removeScope(info.scopeManager, scope);
|
|
2362
|
-
}
|
|
2363
|
-
}
|
|
2364
|
-
function addVirtualReference(node, variable, scope, status) {
|
|
2365
|
-
const reference = new ReferenceClass(
|
|
2366
|
-
node,
|
|
2367
|
-
scope,
|
|
2368
|
-
status.write && status.read ? READ_WRITE_FLAG : status.write ? WRITE_FLAG : READ_FLAG,
|
|
2369
|
-
void 0,
|
|
2370
|
-
// writeExpr
|
|
2371
|
-
void 0,
|
|
2372
|
-
// maybeImplicitGlobal
|
|
2373
|
-
void 0,
|
|
2374
|
-
// init
|
|
2375
|
-
status.typeRef ? REFERENCE_TYPE_TYPE_FLAG : REFERENCE_TYPE_VALUE_FLAG
|
|
2376
|
-
);
|
|
2377
|
-
reference.astroVirtualReference = true;
|
|
2378
|
-
addReference(variable.references, reference);
|
|
2379
|
-
reference.resolved = variable;
|
|
2380
|
-
if (status.forceUsed) {
|
|
2381
|
-
variable.eslintUsed = true;
|
|
2382
|
-
}
|
|
2383
|
-
return reference;
|
|
2384
|
-
}
|
|
2385
|
-
function addGlobalVariable(reference, scopeManager) {
|
|
2386
|
-
const globalScope = scopeManager.globalScope;
|
|
2387
|
-
const name2 = reference.identifier.name;
|
|
2388
|
-
let variable = globalScope.set.get(name2);
|
|
2389
|
-
if (!variable) {
|
|
2390
|
-
variable = new VariableClass(name2, globalScope);
|
|
2391
|
-
globalScope.variables.push(variable);
|
|
2392
|
-
globalScope.set.set(name2, variable);
|
|
2393
|
-
}
|
|
2394
|
-
reference.resolved = variable;
|
|
2395
|
-
variable.references.push(reference);
|
|
2396
|
-
return variable;
|
|
2397
|
-
}
|
|
2398
|
-
function removeReferenceFromThrough(reference, baseScope) {
|
|
2399
|
-
const variable = reference.resolved;
|
|
2400
|
-
const name2 = reference.identifier.name;
|
|
2401
|
-
let scope = baseScope;
|
|
2402
|
-
while (scope) {
|
|
2403
|
-
for (const ref of [...scope.through]) {
|
|
2404
|
-
if (reference === ref) {
|
|
2405
|
-
scope.through.splice(scope.through.indexOf(ref), 1);
|
|
2406
|
-
} else if (ref.identifier.name === name2) {
|
|
2407
|
-
ref.resolved = variable;
|
|
2408
|
-
if (!variable.references.includes(ref)) {
|
|
2409
|
-
addReference(variable.references, ref);
|
|
2410
|
-
}
|
|
2411
|
-
scope.through.splice(scope.through.indexOf(ref), 1);
|
|
2412
|
-
}
|
|
2413
|
-
}
|
|
2414
|
-
scope = scope.upper;
|
|
2415
|
-
}
|
|
2416
|
-
}
|
|
2417
|
-
function removeScope(scopeManager, scope) {
|
|
2418
|
-
for (const childScope of scope.childScopes) {
|
|
2419
|
-
removeScope(scopeManager, childScope);
|
|
2420
|
-
}
|
|
2421
|
-
while (scope.references[0]) {
|
|
2422
|
-
removeReference(scope.references[0], scope);
|
|
2423
|
-
}
|
|
2424
|
-
const upper = scope.upper;
|
|
2425
|
-
if (upper) {
|
|
2426
|
-
const index2 = upper.childScopes.indexOf(scope);
|
|
2427
|
-
if (index2 >= 0) {
|
|
2428
|
-
upper.childScopes.splice(index2, 1);
|
|
2429
|
-
}
|
|
2430
|
-
}
|
|
2431
|
-
const index = scopeManager.scopes.indexOf(scope);
|
|
2432
|
-
if (index >= 0) {
|
|
2433
|
-
scopeManager.scopes.splice(index, 1);
|
|
2434
|
-
}
|
|
2435
|
-
}
|
|
2436
|
-
function removeReference(reference, baseScope) {
|
|
2437
|
-
if (reference.resolved) {
|
|
2438
|
-
if (reference.resolved.defs.some((d) => d.name === reference.identifier)) {
|
|
2439
|
-
const varIndex = baseScope.variables.indexOf(reference.resolved);
|
|
2440
|
-
if (varIndex >= 0) {
|
|
2441
|
-
baseScope.variables.splice(varIndex, 1);
|
|
2442
|
-
}
|
|
2443
|
-
const name2 = reference.identifier.name;
|
|
2444
|
-
if (reference.resolved === baseScope.set.get(name2)) {
|
|
2445
|
-
baseScope.set.delete(name2);
|
|
2446
|
-
}
|
|
2447
|
-
} else {
|
|
2448
|
-
const refIndex = reference.resolved.references.indexOf(reference);
|
|
2449
|
-
if (refIndex >= 0) {
|
|
2450
|
-
reference.resolved.references.splice(refIndex, 1);
|
|
2451
|
-
}
|
|
2452
|
-
}
|
|
2453
|
-
}
|
|
2454
|
-
let scope = baseScope;
|
|
2455
|
-
while (scope) {
|
|
2456
|
-
const refIndex = scope.references.indexOf(reference);
|
|
2457
|
-
if (refIndex >= 0) {
|
|
2458
|
-
scope.references.splice(refIndex, 1);
|
|
2459
|
-
}
|
|
2460
|
-
const throughIndex = scope.through.indexOf(reference);
|
|
2461
|
-
if (throughIndex >= 0) {
|
|
2462
|
-
scope.through.splice(throughIndex, 1);
|
|
2463
|
-
}
|
|
2464
|
-
scope = scope.upper;
|
|
2465
|
-
}
|
|
2466
|
-
}
|
|
2467
|
-
function removeIdentifierVariable(node, scope) {
|
|
2468
|
-
for (let varIndex = 0; varIndex < scope.variables.length; varIndex++) {
|
|
2469
|
-
const variable = scope.variables[varIndex];
|
|
2470
|
-
const defIndex = variable.defs.findIndex((def) => def.name === node);
|
|
2471
|
-
if (defIndex < 0) {
|
|
2472
|
-
continue;
|
|
2473
|
-
}
|
|
2474
|
-
variable.defs.splice(defIndex, 1);
|
|
2475
|
-
if (variable.defs.length === 0) {
|
|
2476
|
-
referencesToThrough(variable.references, scope);
|
|
2477
|
-
variable.references.forEach((r) => {
|
|
2478
|
-
if (r.init)
|
|
2479
|
-
r.init = false;
|
|
2480
|
-
r.resolved = null;
|
|
2481
|
-
});
|
|
2482
|
-
scope.variables.splice(varIndex, 1);
|
|
2483
|
-
const name2 = node.name;
|
|
2484
|
-
if (variable === scope.set.get(name2)) {
|
|
2485
|
-
scope.set.delete(name2);
|
|
2486
|
-
}
|
|
2487
|
-
} else {
|
|
2488
|
-
const idIndex = variable.identifiers.indexOf(node);
|
|
2489
|
-
if (idIndex >= 0) {
|
|
2490
|
-
variable.identifiers.splice(idIndex, 1);
|
|
2491
|
-
}
|
|
2492
|
-
}
|
|
2493
|
-
return;
|
|
2494
|
-
}
|
|
2495
|
-
}
|
|
2496
|
-
function removeIdentifierReference(node, scope) {
|
|
2497
|
-
const reference = scope.references.find((ref) => ref.identifier === node);
|
|
2498
|
-
if (reference) {
|
|
2499
|
-
removeReference(reference, scope);
|
|
2500
|
-
return true;
|
|
2501
|
-
}
|
|
2502
|
-
const location = node.range[0];
|
|
2503
|
-
const pendingScopes = [];
|
|
2504
|
-
for (const childScope of scope.childScopes) {
|
|
2505
|
-
const range = childScope.block.range;
|
|
2506
|
-
if (range[0] <= location && location < range[1]) {
|
|
2507
|
-
if (removeIdentifierReference(node, childScope)) {
|
|
2508
|
-
return true;
|
|
2509
|
-
}
|
|
2510
|
-
} else {
|
|
2511
|
-
pendingScopes.push(childScope);
|
|
2512
|
-
}
|
|
2513
|
-
}
|
|
2514
|
-
for (const childScope of pendingScopes) {
|
|
2515
|
-
if (removeIdentifierReference(node, childScope)) {
|
|
2516
|
-
return true;
|
|
2517
|
-
}
|
|
2518
|
-
}
|
|
2519
|
-
return false;
|
|
2520
|
-
}
|
|
2521
|
-
function getInnermostScopeFromNode(scopeManager, currentNode) {
|
|
2522
|
-
return getInnermostScope(
|
|
2523
|
-
getScopeFromNode(scopeManager, currentNode),
|
|
2524
|
-
currentNode
|
|
2525
|
-
);
|
|
2526
|
-
}
|
|
2527
|
-
function getScopeFromNode(scopeManager, currentNode) {
|
|
2528
|
-
let node = currentNode;
|
|
2529
|
-
for (; node; node = node.parent || null) {
|
|
2530
|
-
const scope = scopeManager.acquire(node, false);
|
|
2531
|
-
if (scope) {
|
|
2532
|
-
if (scope.type === "function-expression-name") {
|
|
2533
|
-
return scope.childScopes[0];
|
|
2534
|
-
}
|
|
2535
|
-
if (scope.type === "global" && node.type === "Program" && node.sourceType === "module") {
|
|
2536
|
-
return scope.childScopes.find((s) => s.type === "module") || scope;
|
|
2537
|
-
}
|
|
2538
|
-
return scope;
|
|
2539
|
-
}
|
|
2540
|
-
}
|
|
2541
|
-
const global = scopeManager.globalScope;
|
|
2542
|
-
return global;
|
|
2543
|
-
}
|
|
2544
|
-
function getInnermostScope(initialScope, node) {
|
|
2545
|
-
for (const childScope of initialScope.childScopes) {
|
|
2546
|
-
const range = childScope.block.range;
|
|
2547
|
-
if (range[0] <= node.range[0] && node.range[1] <= range[1]) {
|
|
2548
|
-
return getInnermostScope(childScope, node);
|
|
2549
|
-
}
|
|
2550
|
-
}
|
|
2551
|
-
return initialScope;
|
|
2552
|
-
}
|
|
2553
|
-
function referencesToThrough(references, baseScope) {
|
|
2554
|
-
let scope = baseScope;
|
|
2555
|
-
while (scope) {
|
|
2556
|
-
addAllReferences(scope.through, references);
|
|
2557
|
-
scope = scope.upper;
|
|
2558
|
-
}
|
|
2559
|
-
}
|
|
2560
|
-
function addAllReferences(list, elements) {
|
|
2561
|
-
addElementsToSortedArray(
|
|
2562
|
-
list,
|
|
2563
|
-
elements,
|
|
2564
|
-
(a, b) => a.identifier.range[0] - b.identifier.range[0]
|
|
2565
|
-
);
|
|
2566
|
-
}
|
|
2567
|
-
function addReference(list, reference) {
|
|
2568
|
-
addElementToSortedArray(
|
|
2569
|
-
list,
|
|
2570
|
-
reference,
|
|
2571
|
-
(a, b) => a.identifier.range[0] - b.identifier.range[0]
|
|
2572
|
-
);
|
|
2573
|
-
}
|
|
2574
|
-
|
|
2575
2670
|
// src/parser/index.ts
|
|
2576
2671
|
function parseForESLint(code, options) {
|
|
2577
2672
|
const { result: resultTemplate, context: ctx } = parseTemplate(
|
|
@@ -2706,7 +2801,7 @@ __export(meta_exports, {
|
|
|
2706
2801
|
|
|
2707
2802
|
// package.json
|
|
2708
2803
|
var name = "astro-eslint-parser";
|
|
2709
|
-
var version = "1.0.
|
|
2804
|
+
var version = "1.0.2";
|
|
2710
2805
|
|
|
2711
2806
|
// src/index.ts
|
|
2712
2807
|
function parseForESLint2(code, options) {
|