astro-eslint-parser 1.0.1 → 1.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/index.d.mts +1 -1
- package/lib/index.d.ts +1 -1
- package/lib/index.js +404 -342
- package/lib/index.mjs +398 -331
- package/package.json +13 -13
package/lib/index.mjs
CHANGED
|
@@ -2,8 +2,7 @@ var __defProp = Object.defineProperty;
|
|
|
2
2
|
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
3
3
|
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
4
4
|
}) : x)(function(x) {
|
|
5
|
-
if (typeof require !== "undefined")
|
|
6
|
-
return require.apply(this, arguments);
|
|
5
|
+
if (typeof require !== "undefined") return require.apply(this, arguments);
|
|
7
6
|
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
8
7
|
});
|
|
9
8
|
var __export = (target, all) => {
|
|
@@ -93,8 +92,7 @@ var TSService = class {
|
|
|
93
92
|
filePath: normalized
|
|
94
93
|
};
|
|
95
94
|
for (const { filePath: targetPath } of [this.currTarget, lastTarget]) {
|
|
96
|
-
if (!targetPath)
|
|
97
|
-
continue;
|
|
95
|
+
if (!targetPath) continue;
|
|
98
96
|
this.fileWatchCallbacks.get(targetPath)?.update();
|
|
99
97
|
}
|
|
100
98
|
const program = this.watch.getProgram().getProgram();
|
|
@@ -466,12 +464,10 @@ function getTSParserNameFromObject(value) {
|
|
|
466
464
|
return null;
|
|
467
465
|
}
|
|
468
466
|
function isTSESLintParserObject(value) {
|
|
469
|
-
if (!isEnhancedParserObject(value))
|
|
470
|
-
return false;
|
|
467
|
+
if (!isEnhancedParserObject(value)) return false;
|
|
471
468
|
if (value.name === "typescript-eslint-parser-for-extra-files")
|
|
472
469
|
return true;
|
|
473
|
-
if (value.meta?.name === "typescript-eslint/parser")
|
|
474
|
-
return true;
|
|
470
|
+
if (value.meta?.name === "typescript-eslint/parser") return true;
|
|
475
471
|
try {
|
|
476
472
|
const result = value.parseForESLint("", {});
|
|
477
473
|
const services = result.services;
|
|
@@ -484,8 +480,15 @@ function isTSESLintParserObject(value) {
|
|
|
484
480
|
}
|
|
485
481
|
|
|
486
482
|
// src/parser/script.ts
|
|
487
|
-
import {
|
|
488
|
-
import {
|
|
483
|
+
import { AST_NODE_TYPES } from "@typescript-eslint/types";
|
|
484
|
+
import {
|
|
485
|
+
analyze as analyzeForTypeScript,
|
|
486
|
+
Reference
|
|
487
|
+
} from "@typescript-eslint/scope-manager";
|
|
488
|
+
import {
|
|
489
|
+
Referencer as BaseReferencer,
|
|
490
|
+
ScopeManager
|
|
491
|
+
} from "eslint-scope";
|
|
489
492
|
|
|
490
493
|
// src/traverse.ts
|
|
491
494
|
function fallbackKeysFilter(key) {
|
|
@@ -528,6 +531,301 @@ function traverseNodes(node, visitor) {
|
|
|
528
531
|
traverse(node, null, visitor);
|
|
529
532
|
}
|
|
530
533
|
|
|
534
|
+
// src/parser/scope/index.ts
|
|
535
|
+
import {
|
|
536
|
+
Reference as ReferenceClass,
|
|
537
|
+
Variable as VariableClass
|
|
538
|
+
} from "@typescript-eslint/scope-manager";
|
|
539
|
+
|
|
540
|
+
// src/util/index.ts
|
|
541
|
+
function sortedLastIndex(array, compare) {
|
|
542
|
+
let lower = 0;
|
|
543
|
+
let upper = array.length;
|
|
544
|
+
while (lower < upper) {
|
|
545
|
+
const mid = Math.floor(lower + (upper - lower) / 2);
|
|
546
|
+
const target = compare(array[mid]);
|
|
547
|
+
if (target < 0) {
|
|
548
|
+
lower = mid + 1;
|
|
549
|
+
} else if (target > 0) {
|
|
550
|
+
upper = mid;
|
|
551
|
+
} else {
|
|
552
|
+
return mid + 1;
|
|
553
|
+
}
|
|
554
|
+
}
|
|
555
|
+
return upper;
|
|
556
|
+
}
|
|
557
|
+
function addElementToSortedArray(array, element, compare) {
|
|
558
|
+
const index = sortedLastIndex(array, (target) => compare(target, element));
|
|
559
|
+
array.splice(index, 0, element);
|
|
560
|
+
}
|
|
561
|
+
function addElementsToSortedArray(array, elements, compare) {
|
|
562
|
+
if (!elements.length) {
|
|
563
|
+
return;
|
|
564
|
+
}
|
|
565
|
+
let last = elements[0];
|
|
566
|
+
let index = sortedLastIndex(array, (target) => compare(target, last));
|
|
567
|
+
for (const element of elements) {
|
|
568
|
+
if (compare(last, element) > 0) {
|
|
569
|
+
index = sortedLastIndex(array, (target) => compare(target, element));
|
|
570
|
+
}
|
|
571
|
+
let e = array[index];
|
|
572
|
+
while (e && compare(e, element) <= 0) {
|
|
573
|
+
e = array[++index];
|
|
574
|
+
}
|
|
575
|
+
array.splice(index, 0, element);
|
|
576
|
+
last = element;
|
|
577
|
+
}
|
|
578
|
+
}
|
|
579
|
+
|
|
580
|
+
// src/parser/scope/index.ts
|
|
581
|
+
var READ_FLAG = 1;
|
|
582
|
+
var WRITE_FLAG = 2;
|
|
583
|
+
var READ_WRITE_FLAG = 3;
|
|
584
|
+
var REFERENCE_TYPE_VALUE_FLAG = 1;
|
|
585
|
+
var REFERENCE_TYPE_TYPE_FLAG = 2;
|
|
586
|
+
function getProgramScope(scopeManager) {
|
|
587
|
+
const globalScope = scopeManager.globalScope;
|
|
588
|
+
return globalScope.childScopes.find((s) => s.type === "module") || globalScope;
|
|
589
|
+
}
|
|
590
|
+
function removeAllScopeAndVariableAndReference(target, info) {
|
|
591
|
+
const targetScopes = /* @__PURE__ */ new Set();
|
|
592
|
+
traverseNodes(target, {
|
|
593
|
+
visitorKeys: info.visitorKeys,
|
|
594
|
+
enterNode(node) {
|
|
595
|
+
const scope = info.scopeManager.acquire(node);
|
|
596
|
+
if (scope) {
|
|
597
|
+
targetScopes.add(scope);
|
|
598
|
+
return;
|
|
599
|
+
}
|
|
600
|
+
if (node.type === "Identifier") {
|
|
601
|
+
let scope2 = getInnermostScopeFromNode(info.scopeManager, node);
|
|
602
|
+
while (scope2 && scope2.block.type !== "Program" && target.range[0] <= scope2.block.range[0] && scope2.block.range[1] <= target.range[1]) {
|
|
603
|
+
scope2 = scope2.upper;
|
|
604
|
+
}
|
|
605
|
+
if (targetScopes.has(scope2)) {
|
|
606
|
+
return;
|
|
607
|
+
}
|
|
608
|
+
removeIdentifierVariable(node, scope2);
|
|
609
|
+
removeIdentifierReference(node, scope2);
|
|
610
|
+
}
|
|
611
|
+
},
|
|
612
|
+
leaveNode() {
|
|
613
|
+
}
|
|
614
|
+
});
|
|
615
|
+
for (const scope of targetScopes) {
|
|
616
|
+
removeScope(info.scopeManager, scope);
|
|
617
|
+
}
|
|
618
|
+
}
|
|
619
|
+
function addVirtualReference(node, variable, scope, status) {
|
|
620
|
+
const reference = new ReferenceClass(
|
|
621
|
+
node,
|
|
622
|
+
scope,
|
|
623
|
+
status.write && status.read ? READ_WRITE_FLAG : status.write ? WRITE_FLAG : READ_FLAG,
|
|
624
|
+
void 0,
|
|
625
|
+
// writeExpr
|
|
626
|
+
void 0,
|
|
627
|
+
// maybeImplicitGlobal
|
|
628
|
+
void 0,
|
|
629
|
+
// init
|
|
630
|
+
status.typeRef ? REFERENCE_TYPE_TYPE_FLAG : REFERENCE_TYPE_VALUE_FLAG
|
|
631
|
+
);
|
|
632
|
+
reference.astroVirtualReference = true;
|
|
633
|
+
addReference(variable.references, reference);
|
|
634
|
+
reference.resolved = variable;
|
|
635
|
+
if (status.forceUsed) {
|
|
636
|
+
variable.eslintUsed = true;
|
|
637
|
+
}
|
|
638
|
+
return reference;
|
|
639
|
+
}
|
|
640
|
+
function addGlobalVariable(reference, scopeManager) {
|
|
641
|
+
const globalScope = scopeManager.globalScope;
|
|
642
|
+
const name2 = reference.identifier.name;
|
|
643
|
+
let variable = globalScope.set.get(name2);
|
|
644
|
+
if (!variable) {
|
|
645
|
+
variable = new VariableClass(name2, globalScope);
|
|
646
|
+
globalScope.variables.push(variable);
|
|
647
|
+
globalScope.set.set(name2, variable);
|
|
648
|
+
}
|
|
649
|
+
reference.resolved = variable;
|
|
650
|
+
variable.references.push(reference);
|
|
651
|
+
return variable;
|
|
652
|
+
}
|
|
653
|
+
function removeReferenceFromThrough(reference, baseScope) {
|
|
654
|
+
const variable = reference.resolved;
|
|
655
|
+
const name2 = reference.identifier.name;
|
|
656
|
+
let scope = baseScope;
|
|
657
|
+
while (scope) {
|
|
658
|
+
for (const ref of [...scope.through]) {
|
|
659
|
+
if (reference === ref) {
|
|
660
|
+
scope.through.splice(scope.through.indexOf(ref), 1);
|
|
661
|
+
} else if (ref.identifier.name === name2) {
|
|
662
|
+
ref.resolved = variable;
|
|
663
|
+
if (!variable.references.includes(ref)) {
|
|
664
|
+
addReference(variable.references, ref);
|
|
665
|
+
}
|
|
666
|
+
scope.through.splice(scope.through.indexOf(ref), 1);
|
|
667
|
+
}
|
|
668
|
+
}
|
|
669
|
+
scope = scope.upper;
|
|
670
|
+
}
|
|
671
|
+
}
|
|
672
|
+
function removeScope(scopeManager, scope) {
|
|
673
|
+
for (const childScope of scope.childScopes) {
|
|
674
|
+
removeScope(scopeManager, childScope);
|
|
675
|
+
}
|
|
676
|
+
while (scope.references[0]) {
|
|
677
|
+
removeReference(scope.references[0], scope);
|
|
678
|
+
}
|
|
679
|
+
const upper = scope.upper;
|
|
680
|
+
if (upper) {
|
|
681
|
+
const index2 = upper.childScopes.indexOf(scope);
|
|
682
|
+
if (index2 >= 0) {
|
|
683
|
+
upper.childScopes.splice(index2, 1);
|
|
684
|
+
}
|
|
685
|
+
}
|
|
686
|
+
const index = scopeManager.scopes.indexOf(scope);
|
|
687
|
+
if (index >= 0) {
|
|
688
|
+
scopeManager.scopes.splice(index, 1);
|
|
689
|
+
}
|
|
690
|
+
}
|
|
691
|
+
function removeReference(reference, baseScope) {
|
|
692
|
+
if (reference.resolved) {
|
|
693
|
+
if (reference.resolved.defs.some((d) => d.name === reference.identifier)) {
|
|
694
|
+
const varIndex = baseScope.variables.indexOf(reference.resolved);
|
|
695
|
+
if (varIndex >= 0) {
|
|
696
|
+
baseScope.variables.splice(varIndex, 1);
|
|
697
|
+
}
|
|
698
|
+
const name2 = reference.identifier.name;
|
|
699
|
+
if (reference.resolved === baseScope.set.get(name2)) {
|
|
700
|
+
baseScope.set.delete(name2);
|
|
701
|
+
}
|
|
702
|
+
} else {
|
|
703
|
+
const refIndex = reference.resolved.references.indexOf(reference);
|
|
704
|
+
if (refIndex >= 0) {
|
|
705
|
+
reference.resolved.references.splice(refIndex, 1);
|
|
706
|
+
}
|
|
707
|
+
}
|
|
708
|
+
}
|
|
709
|
+
let scope = baseScope;
|
|
710
|
+
while (scope) {
|
|
711
|
+
const refIndex = scope.references.indexOf(reference);
|
|
712
|
+
if (refIndex >= 0) {
|
|
713
|
+
scope.references.splice(refIndex, 1);
|
|
714
|
+
}
|
|
715
|
+
const throughIndex = scope.through.indexOf(reference);
|
|
716
|
+
if (throughIndex >= 0) {
|
|
717
|
+
scope.through.splice(throughIndex, 1);
|
|
718
|
+
}
|
|
719
|
+
scope = scope.upper;
|
|
720
|
+
}
|
|
721
|
+
}
|
|
722
|
+
function removeIdentifierVariable(node, scope) {
|
|
723
|
+
for (let varIndex = 0; varIndex < scope.variables.length; varIndex++) {
|
|
724
|
+
const variable = scope.variables[varIndex];
|
|
725
|
+
const defIndex = variable.defs.findIndex((def) => def.name === node);
|
|
726
|
+
if (defIndex < 0) {
|
|
727
|
+
continue;
|
|
728
|
+
}
|
|
729
|
+
variable.defs.splice(defIndex, 1);
|
|
730
|
+
if (variable.defs.length === 0) {
|
|
731
|
+
referencesToThrough(variable.references, scope);
|
|
732
|
+
variable.references.forEach((r) => {
|
|
733
|
+
if (r.init) r.init = false;
|
|
734
|
+
r.resolved = null;
|
|
735
|
+
});
|
|
736
|
+
scope.variables.splice(varIndex, 1);
|
|
737
|
+
const name2 = node.name;
|
|
738
|
+
if (variable === scope.set.get(name2)) {
|
|
739
|
+
scope.set.delete(name2);
|
|
740
|
+
}
|
|
741
|
+
} else {
|
|
742
|
+
const idIndex = variable.identifiers.indexOf(node);
|
|
743
|
+
if (idIndex >= 0) {
|
|
744
|
+
variable.identifiers.splice(idIndex, 1);
|
|
745
|
+
}
|
|
746
|
+
}
|
|
747
|
+
return;
|
|
748
|
+
}
|
|
749
|
+
}
|
|
750
|
+
function removeIdentifierReference(node, scope) {
|
|
751
|
+
const reference = scope.references.find((ref) => ref.identifier === node);
|
|
752
|
+
if (reference) {
|
|
753
|
+
removeReference(reference, scope);
|
|
754
|
+
return true;
|
|
755
|
+
}
|
|
756
|
+
const location = node.range[0];
|
|
757
|
+
const pendingScopes = [];
|
|
758
|
+
for (const childScope of scope.childScopes) {
|
|
759
|
+
const range = childScope.block.range;
|
|
760
|
+
if (range[0] <= location && location < range[1]) {
|
|
761
|
+
if (removeIdentifierReference(node, childScope)) {
|
|
762
|
+
return true;
|
|
763
|
+
}
|
|
764
|
+
} else {
|
|
765
|
+
pendingScopes.push(childScope);
|
|
766
|
+
}
|
|
767
|
+
}
|
|
768
|
+
for (const childScope of pendingScopes) {
|
|
769
|
+
if (removeIdentifierReference(node, childScope)) {
|
|
770
|
+
return true;
|
|
771
|
+
}
|
|
772
|
+
}
|
|
773
|
+
return false;
|
|
774
|
+
}
|
|
775
|
+
function getInnermostScopeFromNode(scopeManager, currentNode) {
|
|
776
|
+
return getInnermostScope(
|
|
777
|
+
getScopeFromNode(scopeManager, currentNode),
|
|
778
|
+
currentNode
|
|
779
|
+
);
|
|
780
|
+
}
|
|
781
|
+
function getScopeFromNode(scopeManager, currentNode) {
|
|
782
|
+
let node = currentNode;
|
|
783
|
+
for (; node; node = node.parent || null) {
|
|
784
|
+
const scope = scopeManager.acquire(node, false);
|
|
785
|
+
if (scope) {
|
|
786
|
+
if (scope.type === "function-expression-name") {
|
|
787
|
+
return scope.childScopes[0];
|
|
788
|
+
}
|
|
789
|
+
if (scope.type === "global" && node.type === "Program" && node.sourceType === "module") {
|
|
790
|
+
return scope.childScopes.find((s) => s.type === "module") || scope;
|
|
791
|
+
}
|
|
792
|
+
return scope;
|
|
793
|
+
}
|
|
794
|
+
}
|
|
795
|
+
const global = scopeManager.globalScope;
|
|
796
|
+
return global;
|
|
797
|
+
}
|
|
798
|
+
function getInnermostScope(initialScope, node) {
|
|
799
|
+
for (const childScope of initialScope.childScopes) {
|
|
800
|
+
const range = childScope.block.range;
|
|
801
|
+
if (range[0] <= node.range[0] && node.range[1] <= range[1]) {
|
|
802
|
+
return getInnermostScope(childScope, node);
|
|
803
|
+
}
|
|
804
|
+
}
|
|
805
|
+
return initialScope;
|
|
806
|
+
}
|
|
807
|
+
function referencesToThrough(references, baseScope) {
|
|
808
|
+
let scope = baseScope;
|
|
809
|
+
while (scope) {
|
|
810
|
+
addAllReferences(scope.through, references);
|
|
811
|
+
scope = scope.upper;
|
|
812
|
+
}
|
|
813
|
+
}
|
|
814
|
+
function addAllReferences(list, elements) {
|
|
815
|
+
addElementsToSortedArray(
|
|
816
|
+
list,
|
|
817
|
+
elements,
|
|
818
|
+
(a, b) => a.identifier.range[0] - b.identifier.range[0]
|
|
819
|
+
);
|
|
820
|
+
}
|
|
821
|
+
function addReference(list, reference) {
|
|
822
|
+
addElementToSortedArray(
|
|
823
|
+
list,
|
|
824
|
+
reference,
|
|
825
|
+
(a, b) => a.identifier.range[0] - b.identifier.range[0]
|
|
826
|
+
);
|
|
827
|
+
}
|
|
828
|
+
|
|
531
829
|
// src/parser/script.ts
|
|
532
830
|
function parseScript(code, ctx, parserOptionsCtx) {
|
|
533
831
|
const result = parseScriptInternal(code, ctx, parserOptionsCtx);
|
|
@@ -586,6 +884,73 @@ ${code}`
|
|
|
586
884
|
patchResult?.terminate();
|
|
587
885
|
}
|
|
588
886
|
}
|
|
887
|
+
var Referencer = class extends BaseReferencer {
|
|
888
|
+
JSXAttribute(node) {
|
|
889
|
+
this.visit(node.value);
|
|
890
|
+
}
|
|
891
|
+
JSXClosingElement() {
|
|
892
|
+
}
|
|
893
|
+
JSXFragment(node) {
|
|
894
|
+
this.visitChildren(node);
|
|
895
|
+
}
|
|
896
|
+
JSXIdentifier(node) {
|
|
897
|
+
const scope = this.currentScope();
|
|
898
|
+
const ref = new Reference(
|
|
899
|
+
node,
|
|
900
|
+
scope,
|
|
901
|
+
READ_FLAG,
|
|
902
|
+
void 0,
|
|
903
|
+
void 0,
|
|
904
|
+
false,
|
|
905
|
+
REFERENCE_TYPE_VALUE_FLAG
|
|
906
|
+
);
|
|
907
|
+
scope.references.push(ref);
|
|
908
|
+
scope.__left.push(ref);
|
|
909
|
+
}
|
|
910
|
+
JSXMemberExpression(node) {
|
|
911
|
+
if (node.object.type !== AST_NODE_TYPES.JSXIdentifier) {
|
|
912
|
+
this.visit(node.object);
|
|
913
|
+
} else {
|
|
914
|
+
if (node.object.name !== "this") {
|
|
915
|
+
this.visit(node.object);
|
|
916
|
+
}
|
|
917
|
+
}
|
|
918
|
+
}
|
|
919
|
+
JSXOpeningElement(node) {
|
|
920
|
+
if (node.name.type === AST_NODE_TYPES.JSXIdentifier) {
|
|
921
|
+
if (node.name.name[0].toUpperCase() === node.name.name[0] || node.name.name === "this") {
|
|
922
|
+
this.visit(node.name);
|
|
923
|
+
}
|
|
924
|
+
} else {
|
|
925
|
+
this.visit(node.name);
|
|
926
|
+
}
|
|
927
|
+
for (const attr of node.attributes) {
|
|
928
|
+
this.visit(attr);
|
|
929
|
+
}
|
|
930
|
+
}
|
|
931
|
+
};
|
|
932
|
+
function analyzeForEcmaScript(tree, providedOptions) {
|
|
933
|
+
const options = Object.assign(
|
|
934
|
+
{
|
|
935
|
+
optimistic: false,
|
|
936
|
+
nodejsScope: false,
|
|
937
|
+
impliedStrict: false,
|
|
938
|
+
sourceType: "script",
|
|
939
|
+
// one of ['script', 'module', 'commonjs']
|
|
940
|
+
ecmaVersion: 5,
|
|
941
|
+
childVisitorKeys: null,
|
|
942
|
+
fallback: "iteration"
|
|
943
|
+
},
|
|
944
|
+
providedOptions
|
|
945
|
+
);
|
|
946
|
+
const scopeManager = new ScopeManager(
|
|
947
|
+
// @ts-expect-error -- No typings
|
|
948
|
+
options
|
|
949
|
+
);
|
|
950
|
+
const referencer = new Referencer(options, scopeManager);
|
|
951
|
+
referencer.visit(tree);
|
|
952
|
+
return scopeManager;
|
|
953
|
+
}
|
|
589
954
|
|
|
590
955
|
// src/parser/sort.ts
|
|
591
956
|
function sort(tokens) {
|
|
@@ -598,7 +963,7 @@ function sort(tokens) {
|
|
|
598
963
|
}
|
|
599
964
|
|
|
600
965
|
// src/parser/process-template.ts
|
|
601
|
-
import { AST_TOKEN_TYPES, AST_NODE_TYPES } from "@typescript-eslint/types";
|
|
966
|
+
import { AST_TOKEN_TYPES, AST_NODE_TYPES as AST_NODE_TYPES2 } from "@typescript-eslint/types";
|
|
602
967
|
|
|
603
968
|
// src/astro/index.ts
|
|
604
969
|
import {
|
|
@@ -774,12 +1139,9 @@ function getEndOffset(node, ctx) {
|
|
|
774
1139
|
if (node.position.end?.offset != null) {
|
|
775
1140
|
return node.position.end.offset;
|
|
776
1141
|
}
|
|
777
|
-
if (isTag(node))
|
|
778
|
-
|
|
779
|
-
if (node.type === "
|
|
780
|
-
return calcExpressionEndOffset(node, ctx);
|
|
781
|
-
if (node.type === "comment")
|
|
782
|
-
return calcCommentEndOffset(node, ctx);
|
|
1142
|
+
if (isTag(node)) return calcTagEndOffset(node, ctx);
|
|
1143
|
+
if (node.type === "expression") return calcExpressionEndOffset(node, ctx);
|
|
1144
|
+
if (node.type === "comment") return calcCommentEndOffset(node, ctx);
|
|
783
1145
|
if (node.type === "frontmatter") {
|
|
784
1146
|
const start = node.position.start.offset;
|
|
785
1147
|
return ctx.code.indexOf("---", start + 3) + 3;
|
|
@@ -957,8 +1319,7 @@ function getTokenInfo(ctx, tokens, position) {
|
|
|
957
1319
|
};
|
|
958
1320
|
function getHTMLEntity(position3) {
|
|
959
1321
|
let codeOffset2 = position3;
|
|
960
|
-
if (ctx.code[codeOffset2++] !== "&")
|
|
961
|
-
return null;
|
|
1322
|
+
if (ctx.code[codeOffset2++] !== "&") return null;
|
|
962
1323
|
let entity = "";
|
|
963
1324
|
const entityDecoder = new EntityDecoder(
|
|
964
1325
|
htmlDecodeTree,
|
|
@@ -1246,7 +1607,7 @@ function processTemplate(ctx, resultTemplate) {
|
|
|
1246
1607
|
script.appendVirtualScript("<>");
|
|
1247
1608
|
fragmentOpened = true;
|
|
1248
1609
|
script.restoreContext.addRestoreNodeProcess((scriptNode, { result }) => {
|
|
1249
|
-
if (scriptNode.type ===
|
|
1610
|
+
if (scriptNode.type === AST_NODE_TYPES2.ExpressionStatement && scriptNode.expression.type === AST_NODE_TYPES2.JSXFragment && scriptNode.range[0] === startOffset && result.ast.body.includes(scriptNode)) {
|
|
1250
1611
|
const index = result.ast.body.indexOf(scriptNode);
|
|
1251
1612
|
const rootFragment = result.ast.body[index] = scriptNode.expression;
|
|
1252
1613
|
delete rootFragment.closingFragment;
|
|
@@ -1284,7 +1645,7 @@ function processTemplate(ctx, resultTemplate) {
|
|
|
1284
1645
|
(_scriptNode, { result }) => {
|
|
1285
1646
|
for (let index = 0; index < result.ast.body.length; index++) {
|
|
1286
1647
|
const st = result.ast.body[index];
|
|
1287
|
-
if (st.type ===
|
|
1648
|
+
if (st.type === AST_NODE_TYPES2.EmptyStatement) {
|
|
1288
1649
|
if (st.range[0] === scriptEnd && st.range[1] === scriptEnd) {
|
|
1289
1650
|
result.ast.body.splice(index, 1);
|
|
1290
1651
|
break;
|
|
@@ -1316,7 +1677,7 @@ function processTemplate(ctx, resultTemplate) {
|
|
|
1316
1677
|
script.appendOriginal(start2);
|
|
1317
1678
|
script.appendVirtualScript("<>");
|
|
1318
1679
|
script.restoreContext.addRestoreNodeProcess((scriptNode) => {
|
|
1319
|
-
if (scriptNode.range[0] === start2 && scriptNode.type ===
|
|
1680
|
+
if (scriptNode.range[0] === start2 && scriptNode.type === AST_NODE_TYPES2.JSXFragment) {
|
|
1320
1681
|
delete scriptNode.openingFragment;
|
|
1321
1682
|
delete scriptNode.closingFragment;
|
|
1322
1683
|
const fragmentNode = scriptNode;
|
|
@@ -1358,7 +1719,7 @@ function processTemplate(ctx, resultTemplate) {
|
|
|
1358
1719
|
script.appendVirtualScript('"');
|
|
1359
1720
|
script.restoreContext.addRestoreNodeProcess(
|
|
1360
1721
|
(scriptNode, context) => {
|
|
1361
|
-
if (scriptNode.type ===
|
|
1722
|
+
if (scriptNode.type === AST_NODE_TYPES2.JSXAttribute && scriptNode.range[0] === attrStart) {
|
|
1362
1723
|
const attrNode = scriptNode;
|
|
1363
1724
|
if (attrNode.value?.type === "Literal" && typeof attrNode.value.value === "string") {
|
|
1364
1725
|
const raw = ctx.code.slice(start2, end);
|
|
@@ -1377,7 +1738,7 @@ function processTemplate(ctx, resultTemplate) {
|
|
|
1377
1738
|
const jsxName = /[\s"'[\]{}]/u.test(attr.name) ? generateUniqueId(attr.name) : attr.name;
|
|
1378
1739
|
script.appendVirtualScript(`${jsxName}=`);
|
|
1379
1740
|
script.restoreContext.addRestoreNodeProcess((scriptNode) => {
|
|
1380
|
-
if (scriptNode.type ===
|
|
1741
|
+
if (scriptNode.type === AST_NODE_TYPES2.JSXAttribute && scriptNode.range[0] === start2) {
|
|
1381
1742
|
const attrNode = scriptNode;
|
|
1382
1743
|
attrNode.type = "AstroShorthandAttribute";
|
|
1383
1744
|
const locs = ctx.getLocations(
|
|
@@ -1401,7 +1762,7 @@ function processTemplate(ctx, resultTemplate) {
|
|
|
1401
1762
|
script.appendOriginal(end);
|
|
1402
1763
|
script.appendVirtualScript("}");
|
|
1403
1764
|
script.restoreContext.addRestoreNodeProcess((scriptNode) => {
|
|
1404
|
-
if (scriptNode.type ===
|
|
1765
|
+
if (scriptNode.type === AST_NODE_TYPES2.JSXAttribute && scriptNode.range[0] === attrStart) {
|
|
1405
1766
|
const attrNode = scriptNode;
|
|
1406
1767
|
attrNode.type = "AstroTemplateLiteralAttribute";
|
|
1407
1768
|
return true;
|
|
@@ -1423,7 +1784,7 @@ function processTemplate(ctx, resultTemplate) {
|
|
|
1423
1784
|
script.appendOriginal(start2);
|
|
1424
1785
|
script.skipOriginalOffset(text.value.length);
|
|
1425
1786
|
script.restoreContext.addRestoreNodeProcess((scriptNode) => {
|
|
1426
|
-
if (scriptNode.type ===
|
|
1787
|
+
if (scriptNode.type === AST_NODE_TYPES2.JSXElement && scriptNode.range[0] === styleNodeStart) {
|
|
1427
1788
|
const textNode = {
|
|
1428
1789
|
type: "AstroRawText",
|
|
1429
1790
|
value: text.value,
|
|
@@ -1455,7 +1816,7 @@ function processTemplate(ctx, resultTemplate) {
|
|
|
1455
1816
|
script.skipOriginalOffset(length - 2);
|
|
1456
1817
|
script.appendOriginal(end);
|
|
1457
1818
|
script.restoreContext.addRestoreNodeProcess((scriptNode, context) => {
|
|
1458
|
-
if (scriptNode.range[0] === start && scriptNode.type ===
|
|
1819
|
+
if (scriptNode.range[0] === start && scriptNode.type === AST_NODE_TYPES2.JSXFragment) {
|
|
1459
1820
|
delete scriptNode.children;
|
|
1460
1821
|
delete scriptNode.openingFragment;
|
|
1461
1822
|
delete scriptNode.closingFragment;
|
|
@@ -1490,7 +1851,7 @@ function processTemplate(ctx, resultTemplate) {
|
|
|
1490
1851
|
script.skipOriginalOffset(length - 2);
|
|
1491
1852
|
script.appendOriginal(end);
|
|
1492
1853
|
script.restoreContext.addRestoreNodeProcess((scriptNode, context) => {
|
|
1493
|
-
if (scriptNode.range[0] === start && scriptNode.type ===
|
|
1854
|
+
if (scriptNode.range[0] === start && scriptNode.type === AST_NODE_TYPES2.JSXFragment) {
|
|
1494
1855
|
delete scriptNode.children;
|
|
1495
1856
|
delete scriptNode.openingFragment;
|
|
1496
1857
|
delete scriptNode.closingFragment;
|
|
@@ -1531,7 +1892,7 @@ function processTemplate(ctx, resultTemplate) {
|
|
|
1531
1892
|
script.restoreContext.addRestoreNodeProcess(
|
|
1532
1893
|
(scriptNode, context) => {
|
|
1533
1894
|
const parent2 = context.getParent(scriptNode);
|
|
1534
|
-
if (scriptNode.range[0] === offset && scriptNode.type ===
|
|
1895
|
+
if (scriptNode.range[0] === offset && scriptNode.type === AST_NODE_TYPES2.JSXClosingElement && parent2.type === AST_NODE_TYPES2.JSXElement) {
|
|
1535
1896
|
parent2.closingElement = null;
|
|
1536
1897
|
return true;
|
|
1537
1898
|
}
|
|
@@ -1607,13 +1968,13 @@ function processTemplate(ctx, resultTemplate) {
|
|
|
1607
1968
|
]);
|
|
1608
1969
|
}
|
|
1609
1970
|
script.restoreContext.addRestoreNodeProcess((scriptNode, context) => {
|
|
1610
|
-
if (scriptNode.type ===
|
|
1971
|
+
if (scriptNode.type === AST_NODE_TYPES2.JSXAttribute && scriptNode.range[0] === targetIndex) {
|
|
1611
1972
|
const baseNameNode = scriptNode.name;
|
|
1612
1973
|
if (colonOffset != null) {
|
|
1613
1974
|
const nameNode = baseNameNode;
|
|
1614
|
-
nameNode.type =
|
|
1975
|
+
nameNode.type = AST_NODE_TYPES2.JSXNamespacedName;
|
|
1615
1976
|
nameNode.namespace = {
|
|
1616
|
-
type:
|
|
1977
|
+
type: AST_NODE_TYPES2.JSXIdentifier,
|
|
1617
1978
|
name: attr.name.slice(0, colonOffset),
|
|
1618
1979
|
...ctx.getLocations(
|
|
1619
1980
|
baseNameNode.range[0],
|
|
@@ -1621,7 +1982,7 @@ function processTemplate(ctx, resultTemplate) {
|
|
|
1621
1982
|
)
|
|
1622
1983
|
};
|
|
1623
1984
|
nameNode.name = {
|
|
1624
|
-
type:
|
|
1985
|
+
type: AST_NODE_TYPES2.JSXIdentifier,
|
|
1625
1986
|
name: attr.name.slice(colonOffset + 1),
|
|
1626
1987
|
...ctx.getLocations(
|
|
1627
1988
|
baseNameNode.range[0] + colonOffset + 1,
|
|
@@ -1632,7 +1993,7 @@ function processTemplate(ctx, resultTemplate) {
|
|
|
1632
1993
|
nameNode.namespace.parent = nameNode;
|
|
1633
1994
|
nameNode.name.parent = nameNode;
|
|
1634
1995
|
} else {
|
|
1635
|
-
if (baseNameNode.type ===
|
|
1996
|
+
if (baseNameNode.type === AST_NODE_TYPES2.JSXIdentifier) {
|
|
1636
1997
|
const nameNode = baseNameNode;
|
|
1637
1998
|
nameNode.name = attr.name;
|
|
1638
1999
|
scriptNode.name = nameNode;
|
|
@@ -1664,48 +2025,8 @@ function processTemplate(ctx, resultTemplate) {
|
|
|
1664
2025
|
while (usedUniqueIds.has(candidate) || ctx.code.includes(candidate)) {
|
|
1665
2026
|
candidate = `$_${base.replace(/\W/g, "_")}${uniqueIdSeq++}`;
|
|
1666
2027
|
}
|
|
1667
|
-
usedUniqueIds.add(candidate);
|
|
1668
|
-
return candidate;
|
|
1669
|
-
}
|
|
1670
|
-
}
|
|
1671
|
-
|
|
1672
|
-
// src/util/index.ts
|
|
1673
|
-
function sortedLastIndex(array, compare) {
|
|
1674
|
-
let lower = 0;
|
|
1675
|
-
let upper = array.length;
|
|
1676
|
-
while (lower < upper) {
|
|
1677
|
-
const mid = Math.floor(lower + (upper - lower) / 2);
|
|
1678
|
-
const target = compare(array[mid]);
|
|
1679
|
-
if (target < 0) {
|
|
1680
|
-
lower = mid + 1;
|
|
1681
|
-
} else if (target > 0) {
|
|
1682
|
-
upper = mid;
|
|
1683
|
-
} else {
|
|
1684
|
-
return mid + 1;
|
|
1685
|
-
}
|
|
1686
|
-
}
|
|
1687
|
-
return upper;
|
|
1688
|
-
}
|
|
1689
|
-
function addElementToSortedArray(array, element, compare) {
|
|
1690
|
-
const index = sortedLastIndex(array, (target) => compare(target, element));
|
|
1691
|
-
array.splice(index, 0, element);
|
|
1692
|
-
}
|
|
1693
|
-
function addElementsToSortedArray(array, elements, compare) {
|
|
1694
|
-
if (!elements.length) {
|
|
1695
|
-
return;
|
|
1696
|
-
}
|
|
1697
|
-
let last = elements[0];
|
|
1698
|
-
let index = sortedLastIndex(array, (target) => compare(target, last));
|
|
1699
|
-
for (const element of elements) {
|
|
1700
|
-
if (compare(last, element) > 0) {
|
|
1701
|
-
index = sortedLastIndex(array, (target) => compare(target, element));
|
|
1702
|
-
}
|
|
1703
|
-
let e = array[index];
|
|
1704
|
-
while (e && compare(e, element) <= 0) {
|
|
1705
|
-
e = array[++index];
|
|
1706
|
-
}
|
|
1707
|
-
array.splice(index, 0, element);
|
|
1708
|
-
last = element;
|
|
2028
|
+
usedUniqueIds.add(candidate);
|
|
2029
|
+
return candidate;
|
|
1709
2030
|
}
|
|
1710
2031
|
}
|
|
1711
2032
|
|
|
@@ -2337,260 +2658,6 @@ var ParserOptionsContext = class {
|
|
|
2337
2658
|
}
|
|
2338
2659
|
};
|
|
2339
2660
|
|
|
2340
|
-
// src/parser/scope/index.ts
|
|
2341
|
-
import {
|
|
2342
|
-
Reference as ReferenceClass,
|
|
2343
|
-
Variable as VariableClass
|
|
2344
|
-
} from "@typescript-eslint/scope-manager";
|
|
2345
|
-
var READ_FLAG = 1;
|
|
2346
|
-
var WRITE_FLAG = 2;
|
|
2347
|
-
var READ_WRITE_FLAG = 3;
|
|
2348
|
-
var REFERENCE_TYPE_VALUE_FLAG = 1;
|
|
2349
|
-
var REFERENCE_TYPE_TYPE_FLAG = 2;
|
|
2350
|
-
function getProgramScope(scopeManager) {
|
|
2351
|
-
const globalScope = scopeManager.globalScope;
|
|
2352
|
-
return globalScope.childScopes.find((s) => s.type === "module") || globalScope;
|
|
2353
|
-
}
|
|
2354
|
-
function removeAllScopeAndVariableAndReference(target, info) {
|
|
2355
|
-
const targetScopes = /* @__PURE__ */ new Set();
|
|
2356
|
-
traverseNodes(target, {
|
|
2357
|
-
visitorKeys: info.visitorKeys,
|
|
2358
|
-
enterNode(node) {
|
|
2359
|
-
const scope = info.scopeManager.acquire(node);
|
|
2360
|
-
if (scope) {
|
|
2361
|
-
targetScopes.add(scope);
|
|
2362
|
-
return;
|
|
2363
|
-
}
|
|
2364
|
-
if (node.type === "Identifier") {
|
|
2365
|
-
let scope2 = getInnermostScopeFromNode(info.scopeManager, node);
|
|
2366
|
-
while (scope2 && scope2.block.type !== "Program" && target.range[0] <= scope2.block.range[0] && scope2.block.range[1] <= target.range[1]) {
|
|
2367
|
-
scope2 = scope2.upper;
|
|
2368
|
-
}
|
|
2369
|
-
if (targetScopes.has(scope2)) {
|
|
2370
|
-
return;
|
|
2371
|
-
}
|
|
2372
|
-
removeIdentifierVariable(node, scope2);
|
|
2373
|
-
removeIdentifierReference(node, scope2);
|
|
2374
|
-
}
|
|
2375
|
-
},
|
|
2376
|
-
leaveNode() {
|
|
2377
|
-
}
|
|
2378
|
-
});
|
|
2379
|
-
for (const scope of targetScopes) {
|
|
2380
|
-
removeScope(info.scopeManager, scope);
|
|
2381
|
-
}
|
|
2382
|
-
}
|
|
2383
|
-
function addVirtualReference(node, variable, scope, status) {
|
|
2384
|
-
const reference = new ReferenceClass(
|
|
2385
|
-
node,
|
|
2386
|
-
scope,
|
|
2387
|
-
status.write && status.read ? READ_WRITE_FLAG : status.write ? WRITE_FLAG : READ_FLAG,
|
|
2388
|
-
void 0,
|
|
2389
|
-
// writeExpr
|
|
2390
|
-
void 0,
|
|
2391
|
-
// maybeImplicitGlobal
|
|
2392
|
-
void 0,
|
|
2393
|
-
// init
|
|
2394
|
-
status.typeRef ? REFERENCE_TYPE_TYPE_FLAG : REFERENCE_TYPE_VALUE_FLAG
|
|
2395
|
-
);
|
|
2396
|
-
reference.astroVirtualReference = true;
|
|
2397
|
-
addReference(variable.references, reference);
|
|
2398
|
-
reference.resolved = variable;
|
|
2399
|
-
if (status.forceUsed) {
|
|
2400
|
-
variable.eslintUsed = true;
|
|
2401
|
-
}
|
|
2402
|
-
return reference;
|
|
2403
|
-
}
|
|
2404
|
-
function addGlobalVariable(reference, scopeManager) {
|
|
2405
|
-
const globalScope = scopeManager.globalScope;
|
|
2406
|
-
const name2 = reference.identifier.name;
|
|
2407
|
-
let variable = globalScope.set.get(name2);
|
|
2408
|
-
if (!variable) {
|
|
2409
|
-
variable = new VariableClass(name2, globalScope);
|
|
2410
|
-
globalScope.variables.push(variable);
|
|
2411
|
-
globalScope.set.set(name2, variable);
|
|
2412
|
-
}
|
|
2413
|
-
reference.resolved = variable;
|
|
2414
|
-
variable.references.push(reference);
|
|
2415
|
-
return variable;
|
|
2416
|
-
}
|
|
2417
|
-
function removeReferenceFromThrough(reference, baseScope) {
|
|
2418
|
-
const variable = reference.resolved;
|
|
2419
|
-
const name2 = reference.identifier.name;
|
|
2420
|
-
let scope = baseScope;
|
|
2421
|
-
while (scope) {
|
|
2422
|
-
for (const ref of [...scope.through]) {
|
|
2423
|
-
if (reference === ref) {
|
|
2424
|
-
scope.through.splice(scope.through.indexOf(ref), 1);
|
|
2425
|
-
} else if (ref.identifier.name === name2) {
|
|
2426
|
-
ref.resolved = variable;
|
|
2427
|
-
if (!variable.references.includes(ref)) {
|
|
2428
|
-
addReference(variable.references, ref);
|
|
2429
|
-
}
|
|
2430
|
-
scope.through.splice(scope.through.indexOf(ref), 1);
|
|
2431
|
-
}
|
|
2432
|
-
}
|
|
2433
|
-
scope = scope.upper;
|
|
2434
|
-
}
|
|
2435
|
-
}
|
|
2436
|
-
function removeScope(scopeManager, scope) {
|
|
2437
|
-
for (const childScope of scope.childScopes) {
|
|
2438
|
-
removeScope(scopeManager, childScope);
|
|
2439
|
-
}
|
|
2440
|
-
while (scope.references[0]) {
|
|
2441
|
-
removeReference(scope.references[0], scope);
|
|
2442
|
-
}
|
|
2443
|
-
const upper = scope.upper;
|
|
2444
|
-
if (upper) {
|
|
2445
|
-
const index2 = upper.childScopes.indexOf(scope);
|
|
2446
|
-
if (index2 >= 0) {
|
|
2447
|
-
upper.childScopes.splice(index2, 1);
|
|
2448
|
-
}
|
|
2449
|
-
}
|
|
2450
|
-
const index = scopeManager.scopes.indexOf(scope);
|
|
2451
|
-
if (index >= 0) {
|
|
2452
|
-
scopeManager.scopes.splice(index, 1);
|
|
2453
|
-
}
|
|
2454
|
-
}
|
|
2455
|
-
function removeReference(reference, baseScope) {
|
|
2456
|
-
if (reference.resolved) {
|
|
2457
|
-
if (reference.resolved.defs.some((d) => d.name === reference.identifier)) {
|
|
2458
|
-
const varIndex = baseScope.variables.indexOf(reference.resolved);
|
|
2459
|
-
if (varIndex >= 0) {
|
|
2460
|
-
baseScope.variables.splice(varIndex, 1);
|
|
2461
|
-
}
|
|
2462
|
-
const name2 = reference.identifier.name;
|
|
2463
|
-
if (reference.resolved === baseScope.set.get(name2)) {
|
|
2464
|
-
baseScope.set.delete(name2);
|
|
2465
|
-
}
|
|
2466
|
-
} else {
|
|
2467
|
-
const refIndex = reference.resolved.references.indexOf(reference);
|
|
2468
|
-
if (refIndex >= 0) {
|
|
2469
|
-
reference.resolved.references.splice(refIndex, 1);
|
|
2470
|
-
}
|
|
2471
|
-
}
|
|
2472
|
-
}
|
|
2473
|
-
let scope = baseScope;
|
|
2474
|
-
while (scope) {
|
|
2475
|
-
const refIndex = scope.references.indexOf(reference);
|
|
2476
|
-
if (refIndex >= 0) {
|
|
2477
|
-
scope.references.splice(refIndex, 1);
|
|
2478
|
-
}
|
|
2479
|
-
const throughIndex = scope.through.indexOf(reference);
|
|
2480
|
-
if (throughIndex >= 0) {
|
|
2481
|
-
scope.through.splice(throughIndex, 1);
|
|
2482
|
-
}
|
|
2483
|
-
scope = scope.upper;
|
|
2484
|
-
}
|
|
2485
|
-
}
|
|
2486
|
-
function removeIdentifierVariable(node, scope) {
|
|
2487
|
-
for (let varIndex = 0; varIndex < scope.variables.length; varIndex++) {
|
|
2488
|
-
const variable = scope.variables[varIndex];
|
|
2489
|
-
const defIndex = variable.defs.findIndex((def) => def.name === node);
|
|
2490
|
-
if (defIndex < 0) {
|
|
2491
|
-
continue;
|
|
2492
|
-
}
|
|
2493
|
-
variable.defs.splice(defIndex, 1);
|
|
2494
|
-
if (variable.defs.length === 0) {
|
|
2495
|
-
referencesToThrough(variable.references, scope);
|
|
2496
|
-
variable.references.forEach((r) => {
|
|
2497
|
-
if (r.init)
|
|
2498
|
-
r.init = false;
|
|
2499
|
-
r.resolved = null;
|
|
2500
|
-
});
|
|
2501
|
-
scope.variables.splice(varIndex, 1);
|
|
2502
|
-
const name2 = node.name;
|
|
2503
|
-
if (variable === scope.set.get(name2)) {
|
|
2504
|
-
scope.set.delete(name2);
|
|
2505
|
-
}
|
|
2506
|
-
} else {
|
|
2507
|
-
const idIndex = variable.identifiers.indexOf(node);
|
|
2508
|
-
if (idIndex >= 0) {
|
|
2509
|
-
variable.identifiers.splice(idIndex, 1);
|
|
2510
|
-
}
|
|
2511
|
-
}
|
|
2512
|
-
return;
|
|
2513
|
-
}
|
|
2514
|
-
}
|
|
2515
|
-
function removeIdentifierReference(node, scope) {
|
|
2516
|
-
const reference = scope.references.find((ref) => ref.identifier === node);
|
|
2517
|
-
if (reference) {
|
|
2518
|
-
removeReference(reference, scope);
|
|
2519
|
-
return true;
|
|
2520
|
-
}
|
|
2521
|
-
const location = node.range[0];
|
|
2522
|
-
const pendingScopes = [];
|
|
2523
|
-
for (const childScope of scope.childScopes) {
|
|
2524
|
-
const range = childScope.block.range;
|
|
2525
|
-
if (range[0] <= location && location < range[1]) {
|
|
2526
|
-
if (removeIdentifierReference(node, childScope)) {
|
|
2527
|
-
return true;
|
|
2528
|
-
}
|
|
2529
|
-
} else {
|
|
2530
|
-
pendingScopes.push(childScope);
|
|
2531
|
-
}
|
|
2532
|
-
}
|
|
2533
|
-
for (const childScope of pendingScopes) {
|
|
2534
|
-
if (removeIdentifierReference(node, childScope)) {
|
|
2535
|
-
return true;
|
|
2536
|
-
}
|
|
2537
|
-
}
|
|
2538
|
-
return false;
|
|
2539
|
-
}
|
|
2540
|
-
function getInnermostScopeFromNode(scopeManager, currentNode) {
|
|
2541
|
-
return getInnermostScope(
|
|
2542
|
-
getScopeFromNode(scopeManager, currentNode),
|
|
2543
|
-
currentNode
|
|
2544
|
-
);
|
|
2545
|
-
}
|
|
2546
|
-
function getScopeFromNode(scopeManager, currentNode) {
|
|
2547
|
-
let node = currentNode;
|
|
2548
|
-
for (; node; node = node.parent || null) {
|
|
2549
|
-
const scope = scopeManager.acquire(node, false);
|
|
2550
|
-
if (scope) {
|
|
2551
|
-
if (scope.type === "function-expression-name") {
|
|
2552
|
-
return scope.childScopes[0];
|
|
2553
|
-
}
|
|
2554
|
-
if (scope.type === "global" && node.type === "Program" && node.sourceType === "module") {
|
|
2555
|
-
return scope.childScopes.find((s) => s.type === "module") || scope;
|
|
2556
|
-
}
|
|
2557
|
-
return scope;
|
|
2558
|
-
}
|
|
2559
|
-
}
|
|
2560
|
-
const global = scopeManager.globalScope;
|
|
2561
|
-
return global;
|
|
2562
|
-
}
|
|
2563
|
-
function getInnermostScope(initialScope, node) {
|
|
2564
|
-
for (const childScope of initialScope.childScopes) {
|
|
2565
|
-
const range = childScope.block.range;
|
|
2566
|
-
if (range[0] <= node.range[0] && node.range[1] <= range[1]) {
|
|
2567
|
-
return getInnermostScope(childScope, node);
|
|
2568
|
-
}
|
|
2569
|
-
}
|
|
2570
|
-
return initialScope;
|
|
2571
|
-
}
|
|
2572
|
-
function referencesToThrough(references, baseScope) {
|
|
2573
|
-
let scope = baseScope;
|
|
2574
|
-
while (scope) {
|
|
2575
|
-
addAllReferences(scope.through, references);
|
|
2576
|
-
scope = scope.upper;
|
|
2577
|
-
}
|
|
2578
|
-
}
|
|
2579
|
-
function addAllReferences(list, elements) {
|
|
2580
|
-
addElementsToSortedArray(
|
|
2581
|
-
list,
|
|
2582
|
-
elements,
|
|
2583
|
-
(a, b) => a.identifier.range[0] - b.identifier.range[0]
|
|
2584
|
-
);
|
|
2585
|
-
}
|
|
2586
|
-
function addReference(list, reference) {
|
|
2587
|
-
addElementToSortedArray(
|
|
2588
|
-
list,
|
|
2589
|
-
reference,
|
|
2590
|
-
(a, b) => a.identifier.range[0] - b.identifier.range[0]
|
|
2591
|
-
);
|
|
2592
|
-
}
|
|
2593
|
-
|
|
2594
2661
|
// src/parser/index.ts
|
|
2595
2662
|
function parseForESLint(code, options) {
|
|
2596
2663
|
const { result: resultTemplate, context: ctx } = parseTemplate(
|
|
@@ -2725,7 +2792,7 @@ __export(meta_exports, {
|
|
|
2725
2792
|
|
|
2726
2793
|
// package.json
|
|
2727
2794
|
var name = "astro-eslint-parser";
|
|
2728
|
-
var version = "1.0.
|
|
2795
|
+
var version = "1.0.3";
|
|
2729
2796
|
|
|
2730
2797
|
// src/index.ts
|
|
2731
2798
|
function parseForESLint2(code, options) {
|