sveast 0.9.6 → 0.9.8
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/README.md +40 -3
- package/a11y.d.ts +1636 -0
- package/a11y.js +36 -0
- package/core.js +1 -1
- package/index.d.ts +48 -11
- package/is-valid-type.js +1 -1
- package/module.js +1 -1
- package/package.json +6 -1
- package/parse-imports-exports.js +1 -1
- package/parse-module.js +1 -1
- package/parse-sections.js +1 -1
- package/parse.js +1 -1
- package/runes.js +1 -1
- package/scope.d.ts +48 -11
- package/scope.js +1 -1
- package/shared-dscc5xg8.js +2 -0
- package/{shared-cs1ezg1f.js → shared-f45stvzk.js} +1 -1
- package/{shared-tapcgcpr.js → shared-k0xcpcmz.js} +1 -1
- package/{shared-qkp49nav.js → shared-nb0h4j83.js} +1 -1
- package/{shared-xwzsb4m8.js → shared-qqrqzz29.js} +1 -1
- package/shared-s46wfvhw.js +10 -0
- package/{shared-nan648gn.js → shared-w3mxqtgj.js} +1 -1
- package/{shared-z9y4mrek.js → shared-x2vs5571.js} +1 -1
- package/{shared-as9z0pac.js → shared-xmc2pnaf.js} +1 -1
- package/typescript.js +1 -1
- package/shared-2pngd0mg.js +0 -10
- package/shared-ke0fgd3r.js +0 -2
package/runes.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import"./shared-dgdrqgdn.js";import{withoutByteOrderMark,isWhitespace,skipWhitespace}from"./shared-5tpb3h6x.js";import{isWordCode,closingBracket,wordCodesEnd}from"./shared-e4gbs4rb.js";import"./shared-m0dcdh24.js";import"./shared-
|
|
1
|
+
import"./shared-dgdrqgdn.js";import{withoutByteOrderMark,isWhitespace,skipWhitespace}from"./shared-5tpb3h6x.js";import{isWordCode,closingBracket,wordCodesEnd}from"./shared-e4gbs4rb.js";import"./shared-m0dcdh24.js";import"./shared-s46wfvhw.js";import"./shared-w3mxqtgj.js";import"./shared-bzqbnvee.js";import"./shared-qqrqzz29.js";import"./shared-f45stvzk.js";import{parse2}from"./shared-nb0h4j83.js";import{parseSections2}from"./shared-xmc2pnaf.js";import{extractIdentifiers2,isReference2,STOP2,SKIP2,walk2}from"./shared-jpvd0875.js";import{RUNES,RUNE_NAMES}from"./shared-m3dr31c3.js";import{lexComponent2}from"./shared-a23q4q40.js";import"./shared-drb44hb9.js";import"./shared-dscc5xg8.js";var REGEX_CANDIDATE=/(?<![\w$])(?:\$(?:state|derived|props|bindable|effect|inspect|host)(?![\w$])|await(?![\w$]))|\\u/g,BOOLEAN_EXPRESSION=/^\{\s*(true|false)\s*\}$/;function isRunesMode(source){let lexed=lexComponent2(source),option=lexed.options?.attributes.find((attribute)=>attribute.name==="runes"),fromOption=option&&booleanValue(option);if(fromOption!==void 0)return fromOption;let text=withoutByteOrderMark(source),scripts=[lexed.instance,lexed.module].flatMap((script)=>script?[script.content]:[]),candidates=!1,inMarkup=!1,onlyAwait=!0;REGEX_CANDIDATE.lastIndex=0;for(let match=REGEX_CANDIDATE.exec(text);match!==null&&!(inMarkup&&!onlyAwait);match=REGEX_CANDIDATE.exec(text)){let at=match.index;candidates=!0,onlyAwait&&=match[0]==="await",inMarkup||=!scripts.some(({start,end})=>at>=start&&at<end)}if(!candidates)return!1;if(!onlyAwait&&option===void 0&&!text.includes("\\u")&&callsRune(text,scripts))return!0;let options={css:!1,comments:!1},ast=inMarkup?parse2(source,options):parseSections2(source,options);if(ast.options?.runes!==void 0)return ast.options.runes;if(onlyAwait)return ast.instance!==void 0&&awaitsOutsideFunctions(ast.instance.content)||awaitsOutsideFunctions(ast.fragment);return usesRunes(ast)}function awaitsOutsideFunctions(root){let awaits=!1;return walk2(root,{enter(node){if(isFunction(node))return SKIP2;if(node.type!=="AwaitExpression")return;return awaits=!0,STOP2}}),awaits}function booleanValue(attribute){if(attribute.value===!0)return!0;let match=BOOLEAN_EXPRESSION.exec(attribute.value);return match?match[1]==="true":void 0}var STORE_NAMES=new Map([...RUNE_NAMES].map((name)=>[name,new RegExp(`(?<![\\w$.])${name.slice(1)}(?![\\w$])`)])),DECLARING_WORDS=new Set("abstract accessor as async class const declare enum export extends function get implements import infer interface is keyof let module namespace new override private protected public readonly satisfies set static type typeof unique var".split(" "));function callsRune(source,scripts){let calls=new Map;for(let{start,end}of scripts){let script=source.slice(0,end);if(closingBracket(script,start,(wordStart,wordEnd)=>{if(script.charCodeAt(wordStart)!==36)return!1;let name=script.slice(wordStart,wordEnd);if(RUNE_NAMES.has(name)&&calls.get(name)!==!1)calls.set(name,isRuneCall(script,wordStart,wordEnd));return!1})!==script.length)return!1}for(let[name,call]of calls)if(call&&!STORE_NAMES.get(name)?.test(source))return!0;return!1}function isRuneCall(source,start,end){let before=start-1;while(before>=0&&isWhitespace(source.charCodeAt(before)))before--;let previous=source.charCodeAt(before);if(previous===35||previous===42||previous===46||previous===58||previous===60||previous===64)return!1;if(isWordCode(previous)){let wordStart=before;while(wordStart>0&&isWordCode(source.charCodeAt(wordStart-1)))wordStart--;if(DECLARING_WORDS.has(source.slice(wordStart,before+1)))return!1}let i=skipWhitespace(source,end);while(source.charCodeAt(i)===46){let wordStart=skipWhitespace(source,i+1),wordEnd=wordCodesEnd(source,wordStart);if(wordEnd===wordStart)return!1;i=skipWhitespace(source,wordEnd)}if(source.charCodeAt(i)===60){if(i=typeArgumentsEnd(source,i),i===-1)return!1;i=skipWhitespace(source,i)}if(source.charCodeAt(i)!==40)return!1;let close=closingBracket(source,i+1);if(source.charCodeAt(close)!==41)return!1;let next=source.charCodeAt(skipWhitespace(source,close+1));return next!==123&&next!==58}function typeArgumentsEnd(source,from){let depth=0,limit=Math.min(source.length,from+2000);for(let i=from;i<limit;i++){let code=source.charCodeAt(i);if(code===34||code===39||code===96||code===47)return-1;if(code===60)depth++;else if(code===62&&source.charCodeAt(i-1)!==61){if(depth--,depth===0)return i+1}}return-1}function usesRunes(ast){let module=ast.module?.content,instance=ast.instance?.content,declared=new Map;if(instance)declare(instance,declared,!0);let moduleDeclared=new Map;if(module)declare(module,moduleDeclared,!1);for(let[name,initial]of moduleDeclared)if(!declared.has(name))declared.set(name,initial);let referenced=[],reference=(name)=>{if(!referenced.includes(name))referenced.push(name)};if(module)collectReferences(module,moduleDeclared,reference);if(instance&&collectReferences(instance,declared,reference))return!0;if(collectReferences(ast.fragment,declared,reference))return!0;for(let name of referenced){let store=name.slice(1);if(!declared.has(store))return!0;let initial=declared.get(store)??null,rune=runeOf(initial,declared);if(!((rune===null||store!=="props"&&rune==="$props")&&!(name==="$derived"&&initial?.type==="ImportDeclaration"&&initial.source.value==="svelte/store")))return!0;declared.set(name,null)}return!1}function collectReferences(root,outer,reference){let ancestors=[],scopes=new Map,unresolved=(name)=>RUNE_NAMES.has(name)&&!outer.has(name)&&!ancestors.some((ancestor)=>declaredIn(ancestor,scopes).has(name)),functions=0,awaits=!1;return walk2(root,{enter(node,parent){if(isFunction(node))functions++;else if(node.type==="AwaitExpression")awaits||=functions===0;let name;if(node.type==="Identifier"&&parent&&!parent.type.startsWith("TS")&&isReference2(node,parent))name=node.name;else if(node.type==="TransitionDirective"||node.type==="AnimateDirective"||node.type==="UseDirective")name=node.name.split(".")[0];else if(node.type==="StyleDirective"&&node.value===!0)name=node.name;if(name!==void 0&&unresolved(name))reference(name);ancestors.push(node)},leave(node){if(ancestors.pop(),isFunction(node))functions--}}),awaits}var NO_NAMES=new Set;function declaredIn(node,scopes){let cached=scopes.get(node);if(cached)return cached;let patterns=[];if(isFunction(node)){if(patterns.push(...node.params),node.type==="FunctionExpression"&&node.id)patterns.push(node.id)}else if(node.type==="CatchClause"&&node.param)patterns.push(node.param);else if(node.type==="SnippetBlock")patterns.push(...node.parameters??[]);else if(node.type==="EachBlock"&&node.context)patterns.push(node.context);if(patterns.length===0&&!isFunction(node))return scopes.set(node,NO_NAMES),NO_NAMES;let names=new Set(patterns.flatMap((pattern)=>extractIdentifiers2(pattern)).map((id)=>id.name));if(isFunction(node)){let{body}=node;walk2(body,{enter(inner){if(inner===body)return;if(inner.type==="VariableDeclaration")for(let declarator of inner.declarations)for(let id of extractIdentifiers2(declarator.id))names.add(id.name);else if((inner.type==="FunctionDeclaration"||inner.type==="ClassDeclaration")&&inner.id)names.add(inner.id.name);return isFunction(inner)?SKIP2:void 0}})}return scopes.set(node,names),names}function isFunction(node){return node.type==="ArrowFunctionExpression"||node.type==="FunctionExpression"||node.type==="FunctionDeclaration"}function declare(program,into,instance){let implicit=[];walk2(program,{enter(node,parent){if(isFunction(node)&&node.type!=="FunctionDeclaration")return SKIP2;let topLevel=parent===program||parent?.type==="ExportNamedDeclaration"||parent?.type==="ExportDefaultDeclaration";if(node.type==="ImportDeclaration"){for(let specifier of node.specifiers)into.set(specifier.local.name,node);return SKIP2}if(node.type==="FunctionDeclaration"||node.type==="ClassDeclaration"){if(topLevel&&node.id)into.set(node.id.name,node);return SKIP2}if(node.type==="VariableDeclaration"){if(node.kind!=="var"&&!topLevel)return SKIP2;for(let declarator of node.declarations)for(let id of extractIdentifiers2(declarator.id))into.set(id.name,topLevel?declarator.init??null:null);return SKIP2}if(instance&&parent===program&&node.type==="LabeledStatement"&&node.label.name==="$"&&node.body.type==="ExpressionStatement"&&node.body.expression.type==="AssignmentExpression"){for(let id of extractIdentifiers2(node.body.expression.left))if(!id.name.startsWith("$"))implicit.push(id)}return}});for(let id of implicit)if(!into.has(id.name))into.set(id.name,null)}function runeOf(initial,declared){if(initial?.type!=="CallExpression")return null;let node=initial.callee,keypath="";while(node.type==="MemberExpression"){if(node.computed||node.property.type!=="Identifier")return null;keypath=`.${node.property.name}${keypath}`,node=node.object}if(node.type==="CallExpression"&&node.callee.type==="Identifier")keypath=`()${keypath}`,node=node.callee;if(node.type!=="Identifier"||declared.has(node.name))return null;return keypath=node.name+keypath,RUNES.has(keypath)?keypath:null}export{isRunesMode};
|
package/scope.d.ts
CHANGED
|
@@ -1,5 +1,16 @@
|
|
|
1
1
|
/** How a {@link Binding} is declared. */
|
|
2
|
-
export type BindingKind = "import" | "var" | "let" | "const" | "using" | "function" | "class" | "enum" | "enum-member" | "namespace" | "param" | "catch" | "reactive" | "each" | "each-index" | "let-directive" | "snippet" | "snippet-param" | "const-tag" | "await-value" | "await-error";
|
|
2
|
+
export type BindingKind = "import" | "var" | "let" | "const" | "using" | "function" | "class" | "enum" | "enum-member" | "namespace" | "param" | "catch" | "reactive" | "each" | "each-index" | "let-directive" | "snippet" | "snippet-param" | "const-tag" | "await-value" | "await-error" | "type" | "interface" | "type-param";
|
|
3
|
+
|
|
4
|
+
/** Options for {@link analyzeScopes}. */
|
|
5
|
+
export interface AnalyzeScopesOptions {
|
|
6
|
+
/**
|
|
7
|
+
* Resolve the names in TypeScript's types too: `type`, `interface` and
|
|
8
|
+
* type parameters declare bindings, in a scope's `types`, and a name in
|
|
9
|
+
* a type is a {@link Reference} with `type: true`. Defaults to `false`,
|
|
10
|
+
* which resolves values only, as svelte's analyzer does.
|
|
11
|
+
*/
|
|
12
|
+
types?: boolean;
|
|
13
|
+
}
|
|
3
14
|
|
|
4
15
|
/** A name declared in a {@link Scope}. */
|
|
5
16
|
export interface Binding {
|
|
@@ -12,12 +23,15 @@ export interface Binding {
|
|
|
12
23
|
* `"each"` and `"each-index"` (`item` and `i` in `{#each items as item,
|
|
13
24
|
* i}`), `"let-directive"`, `"snippet"` (its name), `"snippet-param"`,
|
|
14
25
|
* `"const-tag"` (`{@const}`), `"await-value"` and `"await-error"` (`{:then
|
|
15
|
-
* value}` and `{:catch error}`).
|
|
26
|
+
* value}` and `{:catch error}`). With `{ types: true }`, `"type"`,
|
|
27
|
+
* `"interface"` and `"type-param"` (a type parameter or `infer U`), which
|
|
28
|
+
* are in a scope's `types`, not its `declarations`, and `"param"` for a
|
|
29
|
+
* parameter of a function type or signature too.
|
|
16
30
|
*/
|
|
17
31
|
readonly kind: BindingKind;
|
|
18
32
|
/**
|
|
19
|
-
* The `Identifier` that declares it; `null` for an each block's index
|
|
20
|
-
*
|
|
33
|
+
* The `Identifier` that declares it; `null` for an each block's index,
|
|
34
|
+
* `let:x` without a value and a type parameter, whose names are strings.
|
|
21
35
|
*/
|
|
22
36
|
readonly node: Identifier | null;
|
|
23
37
|
/**
|
|
@@ -25,14 +39,17 @@ export interface Binding {
|
|
|
25
39
|
* `VariableDeclarator`, the function or class, the function a
|
|
26
40
|
* parameter belongs to, the `CatchClause`, the `LabeledStatement` of
|
|
27
41
|
* `$:`, the `EachBlock`, `LetDirective`, `SnippetBlock` or `AwaitBlock`,
|
|
28
|
-
* the enum, enum member or namespace, or `import a = b
|
|
42
|
+
* the enum, enum member or namespace, or `import a = b`; the type
|
|
43
|
+
* alias, interface or `TSTypeParameter`, or the function type or
|
|
44
|
+
* signature a parameter belongs to.
|
|
29
45
|
*/
|
|
30
46
|
readonly declaration: AST.SvelteNode;
|
|
31
47
|
/**
|
|
32
48
|
* What it starts as, as svelte's analyzer has it: a variable's
|
|
33
49
|
* initializer, the function or class, the `ImportDeclaration`, the
|
|
34
50
|
* `SnippetBlock` for a snippet's name, the `EachBlock` for an index,
|
|
35
|
-
* the right side of `$: x = ...`, an enum member's initializer
|
|
51
|
+
* the right side of `$: x = ...`, an enum member's initializer, the type
|
|
52
|
+
* alias or interface. For a
|
|
36
53
|
* prop destructured from `$props()`, its default, without `$bindable`:
|
|
37
54
|
* `"md"` in `let { size = "md" } = $props()` or in `let { size =
|
|
38
55
|
* $bindable("md") } = $props()`. `null` otherwise.
|
|
@@ -96,6 +113,12 @@ export interface Reference {
|
|
|
96
113
|
* `$count = 1` mutates it.
|
|
97
114
|
*/
|
|
98
115
|
readonly store: boolean;
|
|
116
|
+
/**
|
|
117
|
+
* Whether it's in a type, or in `export type { a }`, where it neither
|
|
118
|
+
* reads, writes nor mutates. Only with `{ types: true }`: `A` in `let
|
|
119
|
+
* a: A`, `a` in `typeof a`, `I` in `implements I`, `N` in `N.T`.
|
|
120
|
+
*/
|
|
121
|
+
readonly type: boolean;
|
|
99
122
|
}
|
|
100
123
|
|
|
101
124
|
/**
|
|
@@ -109,13 +132,26 @@ export interface Scope {
|
|
|
109
132
|
*/
|
|
110
133
|
readonly node: AST.SvelteNode | null;
|
|
111
134
|
readonly parent: Scope | null;
|
|
112
|
-
/**
|
|
135
|
+
/**
|
|
136
|
+
* Its own bindings, by name, in the order they're declared: the values,
|
|
137
|
+
* including imports, classes, enums and namespaces, which are types too.
|
|
138
|
+
*/
|
|
113
139
|
readonly declarations: ReadonlyMap<string, Binding>;
|
|
114
140
|
/**
|
|
115
|
-
*
|
|
116
|
-
*
|
|
141
|
+
* Its own type-only bindings, by name: `type`, `interface` and type
|
|
142
|
+
* parameters. Empty unless `{ types: true }`.
|
|
143
|
+
*/
|
|
144
|
+
readonly types: ReadonlyMap<string, Binding>;
|
|
145
|
+
/**
|
|
146
|
+
* The binding `name` refers to here as a value, declared in this scope
|
|
147
|
+
* or one around it; `null` if none does.
|
|
117
148
|
*/
|
|
118
149
|
get(name: string): Binding | null;
|
|
150
|
+
/**
|
|
151
|
+
* The binding `name` refers to here as a type: a `type`, `interface` or
|
|
152
|
+
* type parameter, or an import, class or enum; `null` if none does.
|
|
153
|
+
*/
|
|
154
|
+
getType(name: string): Binding | null;
|
|
119
155
|
}
|
|
120
156
|
|
|
121
157
|
/** What {@link analyzeScopes} found. */
|
|
@@ -171,7 +207,8 @@ export interface Scopes {
|
|
|
171
207
|
* prop is passed as.
|
|
172
208
|
*
|
|
173
209
|
* Names in TypeScript types aren't references, and types aren't
|
|
174
|
-
* declarations: `interface` and `type` declare nothing
|
|
210
|
+
* declarations: `interface` and `type` declare nothing, unless `{ types:
|
|
211
|
+
* true }`, which resolves the names in types too. A top-level
|
|
175
212
|
* snippet is declared in the markup's scope, as in svelte's analyzer, so
|
|
176
213
|
* a `<script>` that uses it refers to a global.
|
|
177
214
|
*
|
|
@@ -188,7 +225,7 @@ export interface Scopes {
|
|
|
188
225
|
*
|
|
189
226
|
* It reads the AST but doesn't change it.
|
|
190
227
|
*/
|
|
191
|
-
export declare function analyzeScopes(ast: AST.Root | Program): Scopes;
|
|
228
|
+
export declare function analyzeScopes(ast: AST.Root | Program, options?: AnalyzeScopesOptions): Scopes;
|
|
192
229
|
|
|
193
230
|
interface BaseNodeWithoutComments {
|
|
194
231
|
type: string;
|
package/scope.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{isNode,fieldsOf}from"./shared-m0dcdh24.js";import{extractIdentifiers2,isReference2,valueVisitorKeys2}from"./shared-jpvd0875.js";import{RUNES,RUNE_NAMES}from"./shared-m3dr31c3.js";class ScopeNode{node;parent;porous;index;declarations=new Map;constructor(node,parent,porous,index){this.node=node,this.parent=parent,this.porous=porous,this.index=index}get(name){for(let scope=this;scope;scope=scope.parent){let binding=scope.declarations.get(name);if(binding!==void 0)return binding}return null}}class BindingNode{name;kind;node;declaration;initial;scope;references=[];rune=null;prop=null;constructor(name,kind,node,declaration,initial,scope){this.name=name,this.kind=kind,this.node=node,this.declaration=declaration,this.initial=initial,this.scope=scope}}class ReferenceNode{node;parent;scope;binding=null;reads;writes;mutates;store=!1;constructor(node,parent,scope,reads,writes,mutates){this.node=node,this.parent=parent,this.scope=scope,this.reads=reads,this.writes=writes,this.mutates=mutates}}var keysByType=Object.assign(Object.create(null),valueVisitorKeys2),ELEMENTS=new Set(["SvelteElement","RegularElement","SvelteFragment","Component","SvelteComponent","SvelteSelf","SlotElement"]),NO_BINDINGS=new Map;function analyzeScopes(ast){return new Analysis(ast,!1)}class Analysis{module;instance;instanceProgram=null;component;ast;scopes=[];scopeIn;synthetic=new Map;recorded;made=new Map;declared=new Map;references=new Map;pending=[];declarators=[];implicit=[];stores=new Map;constructor(ast,record){if(this.ast=ast,this.scopeIn=record?new Map:null,ast.type==="Program")this.component=!1,this.module=this.scope(ast,null,!1),this.instance=this.module,this.made.set(ast,this.module),this.visit(ast,null,this.module);else{this.component=!0;let module=ast.module?.content??null,instance=ast.instance?.content??null;this.module=this.scope(module,null,!1),this.instance=this.scope(instance,this.module,!1),this.instanceProgram=instance,this.scopeIn?.set(ast,this.module);for(let[script,scope]of[[ast.module,this.module],[ast.instance,this.instance]]){if(script===void 0)continue;this.scopeIn?.set(script,scope),this.made.set(script.content,scope);for(let attribute of script.attributes)this.visit(attribute,script,scope);this.visit(script.content,script,scope)}this.visit(ast.fragment,ast,this.instance)}this.declareImplicit(),this.resolve(),this.findRunesAndProps()}scopeOf(node){let synthetic=this.synthetic.get(node);if(synthetic!==void 0)return synthetic;if(this.scopeIn!==null)return this.scopeIn.get(node)??null;this.recorded??=new Analysis(this.ast,!0);let recorded=this.recorded.scopeIn?.get(node);return recorded===void 0?null:this.scopes[recorded.index]}scope(node,parent,porous){let scope=new ScopeNode(node,parent,porous,this.scopes.length);return this.scopes.push(scope),scope}bindingOf(node){return this.declared.get(node)??this.references.get(node)?.binding??null}referenceOf(node){return this.references.get(node)??null}declaredIn(node){return this.made.get(node)?.declarations??NO_BINDINGS}child(scope,node,porous){let made=this.scope(node,scope,porous);return this.made.set(node,made),made}declare(scope,node,name,kind,declaration,initial){let target=scope;if(kind==="var")while(target.porous&&target.parent!==null)target=target.parent;let existing=target.declarations.get(name);if(existing!==void 0&&existing.declaration.type!=="TSDeclareFunction"){if(node!==null)this.declared.set(node,existing);return}let binding=new BindingNode(name,kind,node,declaration,initial,target);if(target.declarations.set(name,binding),node!==null)this.declared.set(node,binding)}reference(node,parent,scope,reads,writes,mutates){this.pending.push(new ReferenceNode(node,parent,scope,reads,writes,mutates))}referenceName(name,start,parent,scope){let root=name.split(".")[0],node={type:"Identifier",name:root,start,end:start+root.length};this.synthetic.set(node,scope),this.reference(node,parent,scope,!0,!1,!1)}visit(node,parent,scope){switch(this.scopeIn?.set(node,scope),node.type){case"Identifier":if(parent!==null&&isReference2(node,parent))this.reference(node,parent,scope,!0,!1,!1);this.visitFields(node,scope);return;case"ImportDeclaration":for(let specifier of node.specifiers){if(this.scopeIn?.set(specifier,scope),this.scopeIn?.set(specifier.local,scope),specifier.type==="ImportSpecifier")this.scopeIn?.set(specifier.imported,scope);this.declare(scope,specifier.local,specifier.local.name,"import",specifier,node)}this.visit(node.source,node,scope);for(let attribute of node.attributes??[])this.visit(attribute,node,scope);return;case"ExportNamedDeclaration":if(node.declaration)this.visit(node.declaration,node,scope);for(let specifier of node.specifiers)if(this.scopeIn?.set(specifier,scope),this.scopeIn?.set(specifier.local,scope),this.scopeIn?.set(specifier.exported,scope),!node.source&&specifier.local.type==="Identifier")this.reference(specifier.local,specifier,scope,!0,!1,!1);if(node.source)this.visit(node.source,node,scope);for(let attribute of node.attributes??[])this.visit(attribute,node,scope);return;case"VariableDeclaration":this.visitDeclaration(node,parent,scope);return;case"FunctionDeclaration":if(node.id)this.scopeIn?.set(node.id,scope),this.declare(scope,node.id,node.id.name,"function",node,node);this.visitFunction(node,this.child(scope,node,!0));return;case"FunctionExpression":{let inner=this.child(scope,node,!0);if(node.id)this.scopeIn?.set(node.id,inner),this.declare(inner,node.id,node.id.name,"function",node,node);this.visitFunction(node,inner);return}case"ArrowFunctionExpression":this.visitFunction(node,this.child(scope,node,!0));return;case"ClassDeclaration":case"ClassExpression":{let inner=scope;if(node.id){if(node.type==="ClassExpression")inner=this.child(scope,node,!1);this.scopeIn?.set(node.id,inner),this.declare(inner,node.id,node.id.name,"class",node,node)}for(let decorator of node.decorators??[])this.visit(decorator,node,scope);if(node.superClass)this.visit(node.superClass,node,inner);this.visit(node.body,node,inner);return}case"BlockStatement":this.visitFields(node,this.child(scope,node,!(parent!==null&&isFunction(parent)&&parent.body===node)));return;case"StaticBlock":this.visitFields(node,this.child(scope,node,!1));return;case"ForStatement":case"SwitchStatement":this.visitFields(node,this.child(scope,node,!0));return;case"ForInStatement":case"ForOfStatement":{let inner=this.child(scope,node,!0);if(node.left.type==="VariableDeclaration")this.visit(node.left,node,inner);else this.visitTarget(node.left,node,inner,!1);this.visit(node.right,node,inner),this.visit(node.body,node,inner);return}case"CatchClause":{if(!node.param)break;let inner=this.child(scope,node,!0);this.declarePattern(node.param,node,inner,"catch",node,null),this.visit(node.body,node,inner);return}case"AssignmentExpression":this.visitTarget(node.left,node,scope,node.operator!=="="),this.visit(node.right,node,scope);return;case"UpdateExpression":this.visitTarget(node.argument,node,scope,!0);return;case"LabeledStatement":if(parent===this.instanceProgram&&node.label.name==="$"){this.visitReactive(node,scope);return}break;case"TSEnumDeclaration":{this.scopeIn?.set(node.id,scope),this.declare(scope,node.id,node.id.name,"enum",node,node);let inner=this.child(scope,node,!1);for(let member of node.members)if(this.scopeIn?.set(member,inner),this.scopeIn?.set(member.id,inner),member.id.type==="Identifier")this.declare(inner,member.id,member.id.name,"enum-member",member,member.initializer??null);for(let member of node.members)if(member.initializer)this.visit(member.initializer,member,inner);return}case"TSModuleDeclaration":if(this.scopeIn?.set(node.id,scope),node.id.type==="Identifier"&&!node.global)this.declare(scope,node.id,node.id.name,"namespace",node,node);if(node.body)this.visit(node.body,node,this.child(scope,node,!1));return;case"TSImportEqualsDeclaration":{this.scopeIn?.set(node.id,scope),this.declare(scope,node.id,node.id.name,"import",node,node.moduleReference);let name=node.moduleReference;while(name.type==="TSQualifiedName")this.scopeIn?.set(name,scope),this.scopeIn?.set(name.right,scope),name=name.left;if(name.type==="Identifier")this.scopeIn?.set(name,scope),this.reference(name,node,scope,!0,!1,!1);else this.visit(name,node,scope);return}case"TSDeclareFunction":if(node.id){if(this.scopeIn?.set(node.id,scope),!scope.declarations.has(node.id.name))this.declare(scope,node.id,node.id.name,"function",node,node)}return;case"Fragment":this.visitFields(node,this.child(scope,node,!1));return;case"RegularElement":case"SvelteElement":case"SlotElement":case"SvelteFragment":this.visitFields(node,this.child(scope,node,!1));return;case"Component":case"SvelteComponent":case"SvelteSelf":this.visitComponent(node,scope);return;case"LetDirective":this.visitLet(node,scope);return;case"EachBlock":this.visitEach(node,scope);return;case"AwaitBlock":this.visitAwait(node,scope);return;case"SnippetBlock":{this.scopeIn?.set(node.expression,scope);let{name}=node.expression;this.declare(scope,node.expression,name,"snippet",node,node);let inner=this.child(scope,node,!1);for(let parameter of node.parameters??[])this.declarePattern(parameter,node,inner,"snippet-param",node,null);this.visit(node.body,node,inner);return}case"BindDirective":if(node.expression.type==="SequenceExpression")break;this.visitTarget(node.expression,node,scope,!0);return;case"TransitionDirective":case"AnimateDirective":case"UseDirective":{this.referenceName(node.name,node.start+prefixLength(node),node,scope);break}case"StyleDirective":if(node.value===!0)this.referenceName(node.name,node.start+6,node,scope);break}this.visitFields(node,scope)}visitFields(node,scope){let keys=keysByType[node.type];if(keys===void 0)throw Error(`unknown node type: ${node.type}`);let fields=fieldsOf(node);for(let k=0;k<keys.length;k++){let value=fields[keys[k]];if(Array.isArray(value))for(let i=0;i<value.length;i++){let child=value[i];if(isNode(child))this.visit(child,node,scope)}else if(isNode(value))this.visit(value,node,scope)}}visitDeclaration(node,parent,scope){let kind=node.kind==="await using"?"using":node.kind;if(parent?.type==="ConstTag")kind="const-tag";for(let declarator of node.declarations)if(this.scopeIn?.set(declarator,scope),this.declarePattern(declarator.id,declarator,scope,kind,declarator,declarator.init??null),this.declarators.push([declarator,scope]),declarator.init)this.visit(declarator.init,declarator,scope)}visitFunction(node,scope){for(let param of node.params){if(param.type==="Identifier"&¶m.name==="this"){this.scopeIn?.set(param,scope);continue}this.declarePattern(param,node,scope,"param",node,null)}this.visit(node.body,node,scope)}declarePattern(pattern,parent,scope,kind,declaration,initial){switch(this.scopeIn?.set(pattern,scope),pattern.type){case"Identifier":this.declare(scope,pattern,pattern.name,kind,declaration,initial);break;case"ObjectPattern":for(let property of pattern.properties){if(this.scopeIn?.set(property,scope),property.type==="RestElement"){this.declarePattern(property,pattern,scope,kind,declaration,initial);continue}if(property.computed)this.visit(property.key,property,scope);else this.scopeIn?.set(property.key,scope);this.declarePattern(property.value,property,scope,kind,declaration,initial)}break;case"ArrayPattern":for(let element of pattern.elements)if(element)this.declarePattern(element,pattern,scope,kind,declaration,initial);break;case"RestElement":this.declarePattern(pattern.argument,pattern,scope,kind,declaration,initial);break;case"AssignmentPattern":this.declarePattern(pattern.left,pattern,scope,kind,declaration,initial),this.visit(pattern.right,pattern,scope);break;case"TSParameterProperty":this.declarePattern(pattern.parameter,pattern,scope,kind,declaration,initial);break;default:this.visit(pattern,parent,scope);return}if("decorators"in pattern&&pattern.decorators)for(let decorator of pattern.decorators)this.visit(decorator,pattern,scope)}visitTarget(target,parent,scope,reads){switch(this.scopeIn?.set(target,scope),target.type){case"Identifier":this.reference(target,parent,scope,reads,!0,!1);return;case"MemberExpression":{let object=target,holder=parent;while(object.type==="MemberExpression"){if(this.scopeIn?.set(object,scope),object.computed)this.visit(object.property,object,scope);else this.scopeIn?.set(object.property,scope);holder=object,object=object.object}if(object.type==="Identifier")this.scopeIn?.set(object,scope),this.reference(object,holder,scope,!0,!1,!0);else this.visit(object,holder,scope);return}case"ObjectPattern":for(let property of target.properties){if(this.scopeIn?.set(property,scope),property.type==="RestElement"){this.visitTarget(property,target,scope,!1);continue}if(property.computed)this.visit(property.key,property,scope);else this.scopeIn?.set(property.key,scope);this.visitTarget(property.value,property,scope,!1)}return;case"ArrayPattern":for(let element of target.elements)if(element)this.visitTarget(element,target,scope,!1);return;case"RestElement":this.visitTarget(target.argument,target,scope,!1);return;case"AssignmentPattern":this.visitTarget(target.left,target,scope,!1),this.visit(target.right,target,scope);return}if(target.type==="TSAsExpression"||target.type==="TSSatisfiesExpression"||target.type==="TSNonNullExpression"||target.type==="TSTypeAssertion"){this.visitTarget(target.expression,target,scope,reads);return}this.visit(target,parent,scope)}visitReactive(node,scope){let inner=this.child(scope,node,!1);this.scopeIn?.set(node.label,scope);let{body}=node;if(body.type==="ExpressionStatement"&&body.expression.type==="AssignmentExpression"){let{left,right}=body.expression;for(let id of extractIdentifiers2(left))if(!id.name.startsWith("$"))this.implicit.push([id,node,right])}this.visit(body,node,inner)}visitComponent(node,scope){if(node.type==="Component")this.referenceName(node.name,node.start+1,node,scope);let slotted=slotOf(node)!==null,defaults=this.scope(node,scope,!1),lets=slotted?scope:defaults;if(this.made.set(node,lets),node.type==="SvelteComponent")this.visit(node.expression,node,scope);for(let attribute of node.attributes)this.visit(attribute,node,attribute.type==="LetDirective"?lets:scope);this.scopeIn?.set(node.fragment,defaults);for(let child of node.fragment.nodes){let slot=slotOf(child);this.visit(child,node.fragment,slot===null?defaults:this.child(scope,child,!1))}}visitLet(node,scope){if(node.expression===null){this.declare(scope,null,node.name,"let-directive",node,null);return}let declare=(expression)=>{switch(this.scopeIn?.set(expression,scope),expression.type){case"Identifier":this.declare(scope,expression,expression.name,"let-directive",node,null);return;case"ObjectExpression":for(let property of expression.properties)if(this.scopeIn?.set(property,scope),property.type==="SpreadElement")declare(property.argument);else this.scopeIn?.set(property.key,scope),declare(property.value);return;case"ArrayExpression":for(let element of expression.elements){if(element===null)continue;if(element.type==="SpreadElement")this.scopeIn?.set(element,scope),declare(element.argument);else declare(element)}}};declare(node.expression)}visitEach(node,scope){if(this.visit(node.expression,node,scope),node.fallback)this.visit(node.fallback,node,scope);let inner=this.child(scope,node,!1);if(node.context)this.declarePattern(node.context,node,inner,"each",node,null);if(node.index!==void 0)this.declare(inner,null,node.index,"each-index",node,node);if(node.key)this.visit(node.key,node,inner);this.scopeIn?.set(node.body,inner);for(let child of node.body.nodes)this.visit(child,node.body,inner)}visitAwait(node,scope){if(this.visit(node.expression,node,scope),node.pending)this.visit(node.pending,node,scope);for(let[fragment,pattern,kind]of[[node.then,node.value,"await-value"],[node.catch,node.error,"await-error"]]){if(fragment===null)continue;this.visit(fragment,node,scope);let inner=this.made.get(fragment);if(pattern!==null&&inner!==void 0)this.declarePattern(pattern,node,inner,kind,node,null)}}declareImplicit(){for(let[id,label,right]of this.implicit)if(this.instance.get(id.name)===null)this.declare(this.instance,id,id.name,"reactive",label,right)}resolve(){let unordered=new Set;for(let reference of this.pending){let{node}=reference,declared=this.declared.get(node);if(declared!==void 0&&declared.kind!=="reactive")continue;this.references.set(node,reference);let binding=reference.scope.get(node.name);if(binding===null&&this.component){let store=this.storeOf(node.name);if(store!==!1)reference.store=!0,reference.mutates||=reference.writes,reference.reads=!0,reference.writes=!1,binding=store}if(binding!==null){reference.binding=binding;let last=binding.references.at(-1);if(last!==void 0&&last.node.start>node.start)unordered.add(binding);binding.references.push(reference)}}for(let binding of unordered)binding.references.sort((a,b)=>a.node.start-b.node.start)}storeOf(name){let cached=this.stores.get(name);if(cached!==void 0)return cached;let store=!1;if(name.length>1&&name.startsWith("$")&&!name.startsWith("$$")){let declaration=this.instance.get(name.slice(1));if(!RUNE_NAMES.has(name))store=declaration;else if(declaration!==null){let initial=declaration.initial,rune=runeOf(initial,this.instance,null);if((rune===null||name!=="$props"&&rune==="$props")&&!(name==="$derived"&&initial?.type==="ImportDeclaration"&&initial.source.value==="svelte/store"))store=declaration}}return this.stores.set(name,store),store}findRunesAndProps(){for(let[declarator,scope]of this.declarators){let rune=runeOf(declarator.init??null,scope,this.references);if(rune===null)continue;for(let id of extractIdentifiers2(declarator.id)){let binding=this.declared.get(id);if(binding?.declaration===declarator)binding.rune=rune}if(rune!=="$props")continue;if(declarator.id.type==="Identifier"){let binding=this.declared.get(declarator.id);if(binding)binding.initial=null;continue}if(declarator.id.type!=="ObjectPattern")continue;for(let property of declarator.id.properties){if(property.type==="RestElement"){for(let id of extractIdentifiers2(property)){let binding=this.declared.get(id);if(binding)binding.initial=null}continue}let value=property.value.type==="AssignmentPattern"?property.value.left:property.value,binding=value.type==="Identifier"?this.declared.get(value):void 0;if(binding===void 0||property.computed)continue;binding.prop=keyName(property.key),binding.initial=property.value.type==="AssignmentPattern"?unwrapBindable(property.value.right):null}}this.findLegacyProps()}findLegacyProps(){if(this.instanceProgram===null)return;for(let statement of this.instanceProgram.body){if(statement.type!=="ExportNamedDeclaration")continue;let{declaration}=statement;if(declaration?.type==="VariableDeclaration"){if(declaration.kind!=="let"&&declaration.kind!=="var")continue;for(let declarator of declaration.declarations)for(let id of extractIdentifiers2(declarator.id)){let binding=this.declared.get(id);if(binding)binding.prop=id.name}continue}if(statement.source)continue;for(let specifier of statement.specifiers){if(specifier.local.type!=="Identifier")continue;let binding=this.instance.declarations.get(specifier.local.name);if(binding?.kind!=="let"&&binding?.kind!=="var")continue;binding.prop=specifier.exported.type==="Identifier"?specifier.exported.name:String(specifier.exported.value)}}}}function isFunction(node){return node.type==="ArrowFunctionExpression"||node.type==="FunctionExpression"||node.type==="FunctionDeclaration"}function slotOf(node){if(!ELEMENTS.has(node.type)||!("attributes"in node))return null;for(let attribute of node.attributes??[])if(attribute.type==="Attribute"&&attribute.name==="slot"&&Array.isArray(attribute.value)&&attribute.value.length===1&&attribute.value[0].type==="Text")return attribute.value[0].data;return null}function runeOf(initial,scope,references){if(initial?.type!=="CallExpression")return null;let node=initial.callee,keypath="";while(node.type==="MemberExpression"){if(node.computed||node.property.type!=="Identifier")return null;keypath=`.${node.property.name}${keypath}`,node=node.object}if(node.type==="CallExpression"&&node.callee.type==="Identifier")keypath=`()${keypath}`,node=node.callee;if(node.type!=="Identifier")return null;if(references!==null){let reference=references.get(node);if(reference?.binding!==null||reference.store)return null}else if(scope.get(node.name)!==null)return null;return keypath=node.name+keypath,RUNES.has(keypath)?keypath:null}function unwrapBindable(node){if(node.type==="CallExpression"&&node.callee.type==="Identifier"&&node.callee.name==="$bindable"){let[argument]=node.arguments;return argument===void 0||argument.type==="SpreadElement"?null:argument}return node}function prefixLength(node){if(node.type==="UseDirective")return 4;if(node.type==="AnimateDirective")return 8;if(node.intro&&node.outro)return 11;return node.intro?3:4}function keyName(key){if(key.type==="Identifier")return key.name;return key.type==="Literal"?String(key.value):null}export{analyzeScopes};
|
|
1
|
+
import{isNode,fieldsOf}from"./shared-m0dcdh24.js";import{extractIdentifiers2,isReference2,visitorKeys2,valueVisitorKeys2}from"./shared-jpvd0875.js";import{RUNES,RUNE_NAMES}from"./shared-m3dr31c3.js";class ScopeNode{node;parent;porous;index;declarations=new Map;types=new Map;constructor(node,parent,porous,index){this.node=node,this.parent=parent,this.porous=porous,this.index=index}get(name){for(let scope=this;scope;scope=scope.parent){let binding=scope.declarations.get(name);if(binding!==void 0)return binding}return null}getType(name){return this.lookup(name,TYPE)}lookup(name,meaning){if(meaning===VALUE)return this.get(name);let kinds=meaning===TYPE?TYPE_KINDS:NAMESPACE_KINDS;for(let scope=this;scope;scope=scope.parent){if(meaning===TYPE){let type=scope.types.get(name);if(type!==void 0)return type}let binding=scope.declarations.get(name);if(binding!==void 0&&kinds.has(binding.kind))return binding}return null}}class BindingNode{name;kind;node;declaration;initial;scope;references=[];rune=null;prop=null;constructor(name,kind,node,declaration,initial,scope){this.name=name,this.kind=kind,this.node=node,this.declaration=declaration,this.initial=initial,this.scope=scope}}class ReferenceNode{node;parent;scope;binding=null;reads;writes;mutates;store=!1;type;meaning;constructor(node,parent,scope,reads,writes,mutates,type,meaning){this.node=node,this.parent=parent,this.scope=scope,this.reads=reads,this.writes=writes,this.mutates=mutates,this.type=type,this.meaning=meaning}}var VALUE=0,TYPE=1,NAMESPACE=2,ANY=3,TYPE_KINDS=new Set(["import","class","enum"]),NAMESPACE_KINDS=new Set(["import","enum","namespace"]);function holdsTypes(type){return type==="MethodDefinition"||type.startsWith("TS")}var keysByType=Object.assign(Object.create(null),valueVisitorKeys2),typedKeysByType=Object.create(null);for(let[type,all]of Object.entries(visitorKeys2)){let values=keysByType[type]??[],types=all.filter((key)=>!values.includes(key));typedKeysByType[type]={values,types:types.length>0?types:null,all}}var ELEMENTS=new Set(["SvelteElement","RegularElement","SvelteFragment","Component","SvelteComponent","SvelteSelf","SlotElement"]),NO_BINDINGS=new Map;function analyzeScopes(ast,options){return new Analysis(ast,!1,options?.types===!0)}class Analysis{module;instance;instanceProgram=null;component;ast;scopes=[];scopeIn;synthetic=new Map;recorded;made=new Map;declared=new Map;references=new Map;pending=[];declarators=[];implicit=[];stores=new Map;types;inType=!1;inferScope=null;constructor(ast,record,types){if(this.ast=ast,this.scopeIn=record?new Map:null,this.types=types,ast.type==="Program")this.component=!1,this.module=this.scope(ast,null,!1),this.instance=this.module,this.made.set(ast,this.module),this.visit(ast,null,this.module);else{this.component=!0;let module=ast.module?.content??null,instance=ast.instance?.content??null;this.module=this.scope(module,null,!1),this.instance=this.scope(instance,this.module,!1),this.instanceProgram=instance,this.scopeIn?.set(ast,this.module);for(let[script,scope]of[[ast.module,this.module],[ast.instance,this.instance]]){if(script===void 0)continue;this.scopeIn?.set(script,scope),this.made.set(script.content,scope);for(let attribute of script.attributes)this.visit(attribute,script,scope);this.visit(script.content,script,scope)}this.visit(ast.fragment,ast,this.instance)}this.declareImplicit(),this.resolve(),this.findRunesAndProps()}scopeOf(node){let synthetic=this.synthetic.get(node);if(synthetic!==void 0)return synthetic;if(this.scopeIn!==null)return this.scopeIn.get(node)??null;this.recorded??=new Analysis(this.ast,!0,this.types);let recorded=this.recorded.scopeIn?.get(node);return recorded===void 0?null:this.scopes[recorded.index]}scope(node,parent,porous){let scope=new ScopeNode(node,parent,porous,this.scopes.length);return this.scopes.push(scope),scope}bindingOf(node){return this.declared.get(node)??this.references.get(node)?.binding??null}referenceOf(node){return this.references.get(node)??null}declaredIn(node){return this.made.get(node)?.declarations??NO_BINDINGS}child(scope,node,porous){let made=this.scope(node,scope,porous);return this.made.set(node,made),made}declare(scope,node,name,kind,declaration,initial){let target=scope;if(kind==="var")while(target.porous&&target.parent!==null)target=target.parent;let declarations=kind==="type"||kind==="interface"||kind==="type-param"?target.types:target.declarations,existing=declarations.get(name);if(existing!==void 0&&existing.declaration.type!=="TSDeclareFunction"){if(node!==null)this.declared.set(node,existing);return}let binding=new BindingNode(name,kind,node,declaration,initial,target);if(declarations.set(name,binding),node!==null)this.declared.set(node,binding)}reference(node,parent,scope,reads,writes,mutates,meaning=VALUE,type=this.inType){this.pending.push(type?new ReferenceNode(node,parent,scope,!1,!1,!1,!0,meaning):new ReferenceNode(node,parent,scope,reads,writes,mutates,!1,meaning))}referenceName(name,start,parent,scope){let root=name.split(".")[0],node={type:"Identifier",name:root,start,end:start+root.length};this.synthetic.set(node,scope),this.reference(node,parent,scope,!0,!1,!1)}visit(node,parent,scope){switch(this.scopeIn?.set(node,scope),node.type){case"Identifier":if(parent!==null&&(this.inType?isReferenceInType(node,parent):isReference2(node,parent)))this.reference(node,parent,scope,!0,!1,!1);this.visitFields(node,scope);return;case"ImportDeclaration":for(let specifier of node.specifiers){if(this.scopeIn?.set(specifier,scope),this.scopeIn?.set(specifier.local,scope),specifier.type==="ImportSpecifier")this.scopeIn?.set(specifier.imported,scope);this.declare(scope,specifier.local,specifier.local.name,"import",specifier,node)}this.visit(node.source,node,scope);for(let attribute of node.attributes??[])this.visit(attribute,node,scope);return;case"ExportNamedDeclaration":if(node.declaration)this.visit(node.declaration,node,scope);for(let specifier of node.specifiers)if(this.scopeIn?.set(specifier,scope),this.scopeIn?.set(specifier.local,scope),this.scopeIn?.set(specifier.exported,scope),!node.source&&specifier.local.type==="Identifier")this.reference(specifier.local,specifier,scope,!0,!1,!1,this.types?ANY:VALUE,this.types&&(node.exportKind==="type"||specifier.exportKind==="type"));if(node.source)this.visit(node.source,node,scope);for(let attribute of node.attributes??[])this.visit(attribute,node,scope);return;case"VariableDeclaration":this.visitDeclaration(node,parent,scope);return;case"FunctionDeclaration":if(node.id)this.scopeIn?.set(node.id,scope),this.declare(scope,node.id,node.id.name,"function",node,node);this.visitFunction(node,this.child(scope,node,!0));return;case"FunctionExpression":{let inner=this.child(scope,node,!0);if(node.id)this.scopeIn?.set(node.id,inner),this.declare(inner,node.id,node.id.name,"function",node,node);this.visitFunction(node,inner);return}case"ArrowFunctionExpression":this.visitFunction(node,this.child(scope,node,!0));return;case"ClassDeclaration":case"ClassExpression":{let generic=this.types&&node.typeParameters!==void 0,inner=node.id&&node.type==="ClassExpression"||generic?this.child(scope,node,!1):scope;if(node.id){let at=node.type==="ClassExpression"?inner:scope;this.scopeIn?.set(node.id,at),this.declare(at,node.id,node.id.name,"class",node,node)}for(let decorator of node.decorators??[])this.visit(decorator,node,scope);if(this.declareTypeParameters(node.typeParameters,inner),node.superClass)this.visit(node.superClass,node,inner);this.visitType(node.superTypeParameters,node,inner),this.visitType(node.implements,node,inner),this.visit(node.body,node,inner);return}case"BlockStatement":this.visitFields(node,this.child(scope,node,!(parent!==null&&isFunction(parent)&&parent.body===node)));return;case"StaticBlock":this.visitFields(node,this.child(scope,node,!1));return;case"ForStatement":case"SwitchStatement":this.visitFields(node,this.child(scope,node,!0));return;case"ForInStatement":case"ForOfStatement":{let inner=this.child(scope,node,!0);if(node.left.type==="VariableDeclaration")this.visit(node.left,node,inner);else this.visitTarget(node.left,node,inner,!1);this.visit(node.right,node,inner),this.visit(node.body,node,inner);return}case"CatchClause":{if(!node.param)break;let inner=this.child(scope,node,!0);this.declarePattern(node.param,node,inner,"catch",node,null),this.visit(node.body,node,inner);return}case"AssignmentExpression":this.visitTarget(node.left,node,scope,node.operator!=="="),this.visit(node.right,node,scope);return;case"UpdateExpression":this.visitTarget(node.argument,node,scope,!0);return;case"LabeledStatement":if(parent===this.instanceProgram&&node.label.name==="$"){this.visitReactive(node,scope);return}break;case"TSEnumDeclaration":{this.scopeIn?.set(node.id,scope),this.declare(scope,node.id,node.id.name,"enum",node,node);let inner=this.child(scope,node,!1);for(let member of node.members)if(this.scopeIn?.set(member,inner),this.scopeIn?.set(member.id,inner),member.id.type==="Identifier")this.declare(inner,member.id,member.id.name,"enum-member",member,member.initializer??null);for(let member of node.members)if(member.initializer)this.visit(member.initializer,member,inner);return}case"TSModuleDeclaration":if(this.scopeIn?.set(node.id,scope),node.id.type==="Identifier"&&!node.global)this.declare(scope,node.id,node.id.name,"namespace",node,node);if(node.body)this.visit(node.body,node,this.child(scope,node,!1));return;case"TSImportEqualsDeclaration":{this.scopeIn?.set(node.id,scope),this.declare(scope,node.id,node.id.name,"import",node,node.moduleReference);let name=node.moduleReference;while(name.type==="TSQualifiedName")this.scopeIn?.set(name,scope),this.scopeIn?.set(name.right,scope),name=name.left;if(name.type==="Identifier")this.scopeIn?.set(name,scope),this.reference(name,node,scope,!0,!1,!1);else this.visit(name,node,scope);return}case"TSDeclareFunction":if(node.id){if(this.scopeIn?.set(node.id,scope),!scope.declarations.has(node.id.name))this.declare(scope,node.id,node.id.name,"function",node,node)}if(this.types)this.visitSignature(node,node.typeParameters,node.params,node.returnType,scope);return;case"Fragment":this.visitFields(node,this.child(scope,node,!1));return;case"RegularElement":case"SvelteElement":case"SlotElement":case"SvelteFragment":this.visitFields(node,this.child(scope,node,!1));return;case"Component":case"SvelteComponent":case"SvelteSelf":this.visitComponent(node,scope);return;case"LetDirective":this.visitLet(node,scope);return;case"EachBlock":this.visitEach(node,scope);return;case"AwaitBlock":this.visitAwait(node,scope);return;case"SnippetBlock":{this.scopeIn?.set(node.expression,scope);let{name}=node.expression;this.declare(scope,node.expression,name,"snippet",node,node);let inner=this.child(scope,node,!1);for(let parameter of node.parameters??[])this.declarePattern(parameter,node,inner,"snippet-param",node,null);this.visit(node.body,node,inner);return}case"BindDirective":if(node.expression.type==="SequenceExpression")break;this.visitTarget(node.expression,node,scope,!0);return;case"TransitionDirective":case"AnimateDirective":case"UseDirective":{this.referenceName(node.name,node.start+prefixLength(node),node,scope);break}case"StyleDirective":if(node.value===!0)this.referenceName(node.name,node.start+6,node,scope);break}if(this.types&&holdsTypes(node.type)&&this.visitTyped(node,scope))return;this.visitFields(node,scope)}visitTyped(node,scope){switch(node.type){case"MethodDefinition":{if(node.typeParameters===void 0)return!1;this.visitChild(node.decorators,node,scope),this.visit(node.key,node,scope);let inner=this.child(scope,node,!1);return this.declareTypeParameters(node.typeParameters,inner),this.visit(node.value,node,inner),!0}case"TSDeclareMethod":return this.visitSignature(node,node.typeParameters,node.params,node.returnType,scope),!0;case"TSFunctionType":case"TSConstructorType":case"TSCallSignatureDeclaration":case"TSConstructSignatureDeclaration":return this.visitSignature(node,node.typeParameters,node.parameters,node.typeAnnotation,scope),!0;case"TSMethodSignature":if(node.computed)this.visit(node.key,node,scope);else this.scopeIn?.set(node.key,scope);return this.visitSignature(node,node.typeParameters,node.parameters,node.typeAnnotation,scope),!0;case"TSTypeAliasDeclaration":case"TSInterfaceDeclaration":{let kind=node.type==="TSTypeAliasDeclaration"?"type":"interface";this.scopeIn?.set(node.id,scope),this.declare(scope,node.id,node.id.name,kind,node,node);let inner=node.typeParameters?this.child(scope,node,!1):scope;if(this.declareTypeParameters(node.typeParameters,inner),node.type==="TSTypeAliasDeclaration")this.visitType(node.typeAnnotation,node,inner);else this.visitType(node.extends,node,inner),this.visitType(node.body,node,inner);return!0}case"TSTypeReference":return this.visitEntityName(node.typeName,node,scope,TYPE),this.visitChild(node.typeArguments,node,scope),!0;case"TSExpressionWithTypeArguments":return this.visitEntityName(node.expression,node,scope,TYPE),this.visitChild(node.typeParameters,node,scope),!0;case"TSTypeQuery":return this.visitEntityName(node.exprName,node,scope,VALUE),this.visitChild(node.typeArguments,node,scope),!0;case"TSImportType":{this.visit(node.argument,node,scope);let name=node.qualifier;while(name!==void 0){if(this.scopeIn?.set(name,scope),name.type!=="TSQualifiedName")break;this.scopeIn?.set(name.right,scope),name=name.left}return this.visitChild(node.typeArguments,node,scope),!0}case"TSMappedType":{let parameter=node.typeParameter;this.scopeIn?.set(parameter,scope),this.visitChild(parameter.constraint,parameter,scope);let inner=this.child(scope,node,!1);return this.declare(inner,null,parameter.name,"type-param",parameter,null),this.visitChild(node.nameType,node,inner),this.visitChild(node.typeAnnotation,node,inner),!0}case"TSConditionalType":{this.visit(node.checkType,node,scope);let inner=this.child(scope,node,!1),outer=this.inferScope;return this.inferScope=inner,this.visit(node.extendsType,node,inner),this.inferScope=outer,this.visit(node.trueType,node,inner),this.visit(node.falseType,node,scope),!0}case"TSInferType":{let parameter=node.typeParameter;return this.scopeIn?.set(parameter,scope),this.declare(this.inferScope??scope,null,parameter.name,"type-param",parameter,null),this.visitChild(parameter.constraint,parameter,scope),!0}}return!1}visitFields(node,scope){if(this.types){this.visitTypedFields(node,scope);return}let keys=keysByType[node.type];if(keys===void 0)throw Error(`unknown node type: ${node.type}`);let fields=fieldsOf(node);for(let k=0;k<keys.length;k++){let value=fields[keys[k]];if(Array.isArray(value))for(let i=0;i<value.length;i++){let child=value[i];if(isNode(child))this.visit(child,node,scope)}else if(isNode(value))this.visit(value,node,scope)}}visitTypedFields(node,scope){let keys=typedKeysByType[node.type];if(keys===void 0)throw Error(`unknown node type: ${node.type}`);if(this.inType){this.visitKeys(node,keys.all,scope);return}if(keys.types!==null){let fields=fieldsOf(node);for(let k=0;k<keys.types.length;k++){let value=fields[keys.types[k]];if(value!=null)this.visitType(value,node,scope)}}this.visitKeys(node,keys.values,scope)}visitKeys(node,keys,scope){let fields=fieldsOf(node);for(let k=0;k<keys.length;k++){let value=fields[keys[k]];if(Array.isArray(value))for(let i=0;i<value.length;i++){let child=value[i];if(isNode(child))this.visit(child,node,scope)}else if(isNode(value))this.visit(value,node,scope)}}visitChild(value,parent,scope){if(Array.isArray(value))for(let i=0;i<value.length;i++){let child=value[i];if(isNode(child))this.visit(child,parent,scope)}else if(isNode(value))this.visit(value,parent,scope)}visitType(value,parent,scope){if(!this.types||value===void 0||value===null)return;let outer=this.inType;this.inType=!0,this.visitChild(value,parent,scope),this.inType=outer}declareTypeParameters(declaration,scope){if(!this.types||declaration===void 0)return;this.scopeIn?.set(declaration,scope);for(let parameter of declaration.params)this.scopeIn?.set(parameter,scope),this.declare(scope,null,parameter.name,"type-param",parameter,null);for(let parameter of declaration.params)this.visitType(parameter.constraint,parameter,scope),this.visitType(parameter.default,parameter,scope)}visitSignature(node,typeParameters,parameters,returnType,scope){let inner=this.child(scope,node,!0);this.declareTypeParameters(typeParameters,inner),this.declareParameters(parameters,node,inner),this.visitType(returnType,node,inner)}declareParameters(parameters,node,scope){for(let param of parameters){if(param.type==="Identifier"&¶m.name==="this"){if(this.scopeIn?.set(param,scope),this.types)this.visitType(param.typeAnnotation,param,scope);continue}this.declarePattern(param,node,scope,"param",node,null)}}visitEntityName(entity,parent,scope,meaning){if(entity.type==="TSImportType"){this.visit(entity,parent,scope);return}let name=entity,holder=parent;while(name.type==="TSQualifiedName")this.scopeIn?.set(name,scope),this.scopeIn?.set(name.right,scope),holder=name,name=name.left;if(this.scopeIn?.set(name,scope),name.name==="this")return;let qualified=name!==entity&&meaning===TYPE;this.reference(name,holder,scope,!0,!1,!1,qualified?NAMESPACE:meaning)}visitDeclaration(node,parent,scope){let kind=node.kind==="await using"?"using":node.kind;if(parent?.type==="ConstTag")kind="const-tag";for(let declarator of node.declarations)if(this.scopeIn?.set(declarator,scope),this.declarePattern(declarator.id,declarator,scope,kind,declarator,declarator.init??null),this.declarators.push([declarator,scope]),declarator.init)this.visit(declarator.init,declarator,scope)}visitFunction(node,scope){if(this.types)this.declareTypeParameters(node.typeParameters,scope);if(this.declareParameters(node.params,node,scope),this.types)this.visitType(node.returnType,node,scope);this.visit(node.body,node,scope)}declarePattern(pattern,parent,scope,kind,declaration,initial){switch(this.scopeIn?.set(pattern,scope),pattern.type){case"Identifier":this.declare(scope,pattern,pattern.name,kind,declaration,initial);break;case"ObjectPattern":for(let property of pattern.properties){if(this.scopeIn?.set(property,scope),property.type==="RestElement"){this.declarePattern(property,pattern,scope,kind,declaration,initial);continue}if(property.computed)this.visit(property.key,property,scope);else this.scopeIn?.set(property.key,scope);this.declarePattern(property.value,property,scope,kind,declaration,initial)}break;case"ArrayPattern":for(let element of pattern.elements)if(element)this.declarePattern(element,pattern,scope,kind,declaration,initial);break;case"RestElement":this.declarePattern(pattern.argument,pattern,scope,kind,declaration,initial);break;case"AssignmentPattern":this.declarePattern(pattern.left,pattern,scope,kind,declaration,initial),this.visit(pattern.right,pattern,scope);break;case"TSParameterProperty":this.declarePattern(pattern.parameter,pattern,scope,kind,declaration,initial);break;default:this.visit(pattern,parent,scope);return}if("decorators"in pattern&&pattern.decorators)for(let decorator of pattern.decorators)this.visit(decorator,pattern,scope);if(this.types&&"typeAnnotation"in pattern&&pattern.typeAnnotation)this.visitType(pattern.typeAnnotation,pattern,scope)}visitTarget(target,parent,scope,reads){switch(this.scopeIn?.set(target,scope),target.type){case"Identifier":this.reference(target,parent,scope,reads,!0,!1);return;case"MemberExpression":{let object=target,holder=parent;while(object.type==="MemberExpression"){if(this.scopeIn?.set(object,scope),object.computed)this.visit(object.property,object,scope);else this.scopeIn?.set(object.property,scope);holder=object,object=object.object}if(object.type==="Identifier")this.scopeIn?.set(object,scope),this.reference(object,holder,scope,!0,!1,!0);else this.visit(object,holder,scope);return}case"ObjectPattern":for(let property of target.properties){if(this.scopeIn?.set(property,scope),property.type==="RestElement"){this.visitTarget(property,target,scope,!1);continue}if(property.computed)this.visit(property.key,property,scope);else this.scopeIn?.set(property.key,scope);this.visitTarget(property.value,property,scope,!1)}return;case"ArrayPattern":for(let element of target.elements)if(element)this.visitTarget(element,target,scope,!1);return;case"RestElement":this.visitTarget(target.argument,target,scope,!1);return;case"AssignmentPattern":this.visitTarget(target.left,target,scope,!1),this.visit(target.right,target,scope);return}if(target.type==="TSAsExpression"||target.type==="TSSatisfiesExpression"||target.type==="TSNonNullExpression"||target.type==="TSTypeAssertion"){if(this.visitTarget(target.expression,target,scope,reads),target.type!=="TSNonNullExpression")this.visitType(target.typeAnnotation,target,scope);return}this.visit(target,parent,scope)}visitReactive(node,scope){let inner=this.child(scope,node,!1);this.scopeIn?.set(node.label,scope);let{body}=node;if(body.type==="ExpressionStatement"&&body.expression.type==="AssignmentExpression"){let{left,right}=body.expression;for(let id of extractIdentifiers2(left))if(!id.name.startsWith("$"))this.implicit.push([id,node,right])}this.visit(body,node,inner)}visitComponent(node,scope){if(node.type==="Component")this.referenceName(node.name,node.start+1,node,scope);let slotted=slotOf(node)!==null,defaults=this.scope(node,scope,!1),lets=slotted?scope:defaults;if(this.made.set(node,lets),node.type==="SvelteComponent")this.visit(node.expression,node,scope);for(let attribute of node.attributes)this.visit(attribute,node,attribute.type==="LetDirective"?lets:scope);this.scopeIn?.set(node.fragment,defaults);for(let child of node.fragment.nodes){let slot=slotOf(child);this.visit(child,node.fragment,slot===null?defaults:this.child(scope,child,!1))}}visitLet(node,scope){if(node.expression===null){this.declare(scope,null,node.name,"let-directive",node,null);return}let declare=(expression)=>{switch(this.scopeIn?.set(expression,scope),expression.type){case"Identifier":this.declare(scope,expression,expression.name,"let-directive",node,null);return;case"ObjectExpression":for(let property of expression.properties)if(this.scopeIn?.set(property,scope),property.type==="SpreadElement")declare(property.argument);else this.scopeIn?.set(property.key,scope),declare(property.value);return;case"ArrayExpression":for(let element of expression.elements){if(element===null)continue;if(element.type==="SpreadElement")this.scopeIn?.set(element,scope),declare(element.argument);else declare(element)}}};declare(node.expression)}visitEach(node,scope){if(this.visit(node.expression,node,scope),node.fallback)this.visit(node.fallback,node,scope);let inner=this.child(scope,node,!1);if(node.context)this.declarePattern(node.context,node,inner,"each",node,null);if(node.index!==void 0)this.declare(inner,null,node.index,"each-index",node,node);if(node.key)this.visit(node.key,node,inner);this.scopeIn?.set(node.body,inner);for(let child of node.body.nodes)this.visit(child,node.body,inner)}visitAwait(node,scope){if(this.visit(node.expression,node,scope),node.pending)this.visit(node.pending,node,scope);for(let[fragment,pattern,kind]of[[node.then,node.value,"await-value"],[node.catch,node.error,"await-error"]]){if(fragment===null)continue;this.visit(fragment,node,scope);let inner=this.made.get(fragment);if(pattern!==null&&inner!==void 0)this.declarePattern(pattern,node,inner,kind,node,null)}}declareImplicit(){for(let[id,label,right]of this.implicit)if(this.instance.get(id.name)===null)this.declare(this.instance,id,id.name,"reactive",label,right)}resolve(){let unordered=new Set;for(let reference of this.pending){let{node}=reference,declared=this.declared.get(node);if(declared!==void 0&&declared.kind!=="reactive")continue;this.references.set(node,reference);let{meaning}=reference,binding;if(meaning===VALUE)binding=reference.scope.get(node.name);else if(meaning!==ANY)binding=reference.scope.lookup(node.name,meaning);else if(reference.type)binding=reference.scope.getType(node.name)??reference.scope.get(node.name);else if(binding=reference.scope.get(node.name),binding===null){if(binding=reference.scope.getType(node.name),binding!==null)reference.type=!0,reference.reads=!1}if(binding===null&&this.component&&meaning!==TYPE){let store=this.storeOf(node.name);if(store!==!1)reference.store=!0,reference.mutates||=reference.writes,reference.reads=!reference.type,reference.writes=!1,binding=store}if(binding!==null){reference.binding=binding;let last=binding.references.at(-1);if(last!==void 0&&last.node.start>node.start)unordered.add(binding);binding.references.push(reference)}}for(let binding of unordered)binding.references.sort((a,b)=>a.node.start-b.node.start)}storeOf(name){let cached=this.stores.get(name);if(cached!==void 0)return cached;let store=!1;if(name.length>1&&name.startsWith("$")&&!name.startsWith("$$")){let declaration=this.instance.get(name.slice(1));if(!RUNE_NAMES.has(name))store=declaration;else if(declaration!==null){let initial=declaration.initial,rune=runeOf(initial,this.instance,null);if((rune===null||name!=="$props"&&rune==="$props")&&!(name==="$derived"&&initial?.type==="ImportDeclaration"&&initial.source.value==="svelte/store"))store=declaration}}return this.stores.set(name,store),store}findRunesAndProps(){for(let[declarator,scope]of this.declarators){let rune=runeOf(declarator.init??null,scope,this.references);if(rune===null)continue;for(let id of extractIdentifiers2(declarator.id)){let binding=this.declared.get(id);if(binding?.declaration===declarator)binding.rune=rune}if(rune!=="$props")continue;if(declarator.id.type==="Identifier"){let binding=this.declared.get(declarator.id);if(binding)binding.initial=null;continue}if(declarator.id.type!=="ObjectPattern")continue;for(let property of declarator.id.properties){if(property.type==="RestElement"){for(let id of extractIdentifiers2(property)){let binding=this.declared.get(id);if(binding)binding.initial=null}continue}let value=property.value.type==="AssignmentPattern"?property.value.left:property.value,binding=value.type==="Identifier"?this.declared.get(value):void 0;if(binding===void 0||property.computed)continue;binding.prop=keyName(property.key),binding.initial=property.value.type==="AssignmentPattern"?unwrapBindable(property.value.right):null}}this.findLegacyProps()}findLegacyProps(){if(this.instanceProgram===null)return;for(let statement of this.instanceProgram.body){if(statement.type!=="ExportNamedDeclaration")continue;let{declaration}=statement;if(declaration?.type==="VariableDeclaration"){if(declaration.kind!=="let"&&declaration.kind!=="var")continue;for(let declarator of declaration.declarations)for(let id of extractIdentifiers2(declarator.id)){let binding=this.declared.get(id);if(binding)binding.prop=id.name}continue}if(statement.source)continue;for(let specifier of statement.specifiers){if(specifier.local.type!=="Identifier")continue;let binding=this.instance.declarations.get(specifier.local.name);if(binding?.kind!=="let"&&binding?.kind!=="var")continue;binding.prop=specifier.exported.type==="Identifier"?specifier.exported.name:String(specifier.exported.value)}}}}function isReferenceInType(node,parent){switch(parent.type){case"TSPropertySignature":case"TSMethodSignature":return parent.computed===!0&&node===parent.key;case"TSTypePredicate":return node===parent.parameterName;default:return isReference2(node,parent)}}function isFunction(node){return node.type==="ArrowFunctionExpression"||node.type==="FunctionExpression"||node.type==="FunctionDeclaration"}function slotOf(node){if(!ELEMENTS.has(node.type)||!("attributes"in node))return null;for(let attribute of node.attributes??[])if(attribute.type==="Attribute"&&attribute.name==="slot"&&Array.isArray(attribute.value)&&attribute.value.length===1&&attribute.value[0].type==="Text")return attribute.value[0].data;return null}function runeOf(initial,scope,references){if(initial?.type!=="CallExpression")return null;let node=initial.callee,keypath="";while(node.type==="MemberExpression"){if(node.computed||node.property.type!=="Identifier")return null;keypath=`.${node.property.name}${keypath}`,node=node.object}if(node.type==="CallExpression"&&node.callee.type==="Identifier")keypath=`()${keypath}`,node=node.callee;if(node.type!=="Identifier")return null;if(references!==null){let reference=references.get(node);if(reference?.binding!==null||reference.store)return null}else if(scope.get(node.name)!==null)return null;return keypath=node.name+keypath,RUNES.has(keypath)?keypath:null}function unwrapBindable(node){if(node.type==="CallExpression"&&node.callee.type==="Identifier"&&node.callee.name==="$bindable"){let[argument]=node.arguments;return argument===void 0||argument.type==="SpreadElement"?null:argument}return node}function prefixLength(node){if(node.type==="UseDirective")return 4;if(node.type==="AnimateDirective")return 8;if(node.intro&&node.outro)return 11;return node.intro?3:4}function keyName(key){if(key.type==="Identifier")return key.name;return key.type==="Literal"?String(key.value):null}export{analyzeScopes};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{definePlugin,hasLineBreak,hasName}from"./shared-2pngd0mg.js";var SKIP_WHITESPACE=/(?:\s|\/\/.*|\/\*[\s\S]*?\*\/)*/g,KEYWORD_TYPES=new Map([["any","TSAnyKeyword"],["bigint","TSBigIntKeyword"],["boolean","TSBooleanKeyword"],["never","TSNeverKeyword"],["null","TSNullKeyword"],["number","TSNumberKeyword"],["object","TSObjectKeyword"],["string","TSStringKeyword"],["symbol","TSSymbolKeyword"],["undefined","TSUndefinedKeyword"],["unknown","TSUnknownKeyword"],["void","TSVoidKeyword"]]),CLASS_MODIFIERS=new Set("public private protected readonly declare abstract override static accessor".split(" ")),PARAMETER_MODIFIERS=new Set("public private protected readonly override".split(" ")),DECLARE_TARGETS=new Set("var let const function class abstract enum interface type namespace module global".split(" ")),DECLARE_FIRST=new Set("var let const function class interface enum".split(" ")),TS_EXPRESSION_WRAPPERS=new Set(["TSAsExpression","TSSatisfiesExpression","TSNonNullExpression","TSTypeAssertion"]),SCOPE_TOP=1,SCOPE_SIMPLE_CATCH=32,SCOPE_CLASS_STATIC_BLOCK=256,BIND_NONE=0,BIND_VAR=1,BIND_LEXICAL=2,BIND_FUNCTION=3,BIND_SIMPLE_CATCH=4,BIND_TS_TYPE=6,BIND_TS_INTERFACE=7,BIND_FLAGS_TS_ENUM=256,BIND_FLAGS_TS_EXPORT_ONLY=1024,BIND_TS_NAMESPACE=8|BIND_FLAGS_TS_EXPORT_ONLY,BIND_TS_ENUM=BIND_LEXICAL|BIND_FLAGS_TS_ENUM,FUNC_STATEMENT=1,FUNC_HANGING_STATEMENT=2,CHAR_PAREN_L=40,CHAR_PAREN_R=41,CHAR_COMMA=44,CHAR_DOT=46,CHAR_COLON=58,CHAR_EQ=61,CHAR_LT=60,CHAR_BRACE_L=123,CHAR_BRACKET_L=91,CHAR_STAR=42,CHAR_HASH=35,CHAR_DQUOTE=34,CHAR_SQUOTE=39,SPECULATION_FAILED=SyntaxError("speculative parse failed"),tsPlugin=definePlugin((Base)=>{let{tokTypes:tt,keywordTypes,isIdentifierChar,isIdentifierStart}=Base.acorn,atType=new Base.acorn.TokenType("@");class TSParser extends Base{inType=!1;$4=!1;$5=!1;$7=null;$k=null;$l=!1;$m=!1;$f=null;$9=[[]];$n=0;$t=0;$o=-1;constructor(options,input,startPos){super(options,input,startPos);let onComment=this.options.onComment;if(typeof onComment==="function")this.options.onComment=(block,text,start,end,startLoc,endLoc)=>{if(start<this.$t)return;this.$t=end,onComment.call(this,block,text,start,end,startLoc,endLoc)}}reset(){this.inType=!1,this.$4=!1,this.$5=!1,this.$7=null,this.$k=null,this.$l=!1,this.$m=!1,this.$f=null,this.$9=[[]],this.$n=0,this.$t=0,this.$o=-1}getTokenFromCode(code){if(code===64)return++this.pos,this.finishToken(atType);return super.getTokenFromCode(code)}readToken_lt_gt(code){if(this.inType)return this.finishOp(tt.relational,1);return super.readToken_lt_gt(code)}$a(fn){let old=this.inType;this.inType=!0;let result=fn();if(this.inType=old,!old&&this.type===tt.relational)this.pos=this.start,this.nextToken();return result}$1(){return this.type===tt.relational&&this.value==="<"}$p(){if(this.type===tt.bitShift&&this.value==="<<")this.pos=this.start+1,this.finishToken(tt.relational,"<");return this.$1()}$c(){return this.type===tt.relational&&this.value===">"}$u(){return this.type===tt.prefix&&this.value==="!"}hasPrecedingLineBreak(){return hasLineBreak(this.input,this.lastTokEnd,this.start)}$d(from=this.pos){return SKIP_WHITESPACE.lastIndex=from,SKIP_WHITESPACE.exec(this.input),SKIP_WHITESPACE.lastIndex}$2(){return this.input.charCodeAt(this.$d())}$3(){let start=this.$d(),end=start;while(end<this.input.length&&isIdentifierChar(this.input.charCodeAt(end)))end++;return this.input.slice(start,end)}$b(){return!hasLineBreak(this.input,this.pos,this.$d())}$14(){return this.$b()&&isIdentifierStart(this.$2())&&!Object.hasOwn(keywordTypes,this.$3())}$15(){return{pos:this.pos,type:this.type,value:this.value,start:this.start,end:this.end,startLoc:this.startLoc,endLoc:this.endLoc,lastTokStart:this.lastTokStart,lastTokEnd:this.lastTokEnd,lastTokStartLoc:this.lastTokStartLoc,lastTokEndLoc:this.lastTokEndLoc,curLine:this.curLine,lineStart:this.lineStart,context:this.context.slice(),exprAllowed:this.exprAllowed,containsEsc:this.containsEsc,inType:this.inType,$4:this.$4,$5:this.$5,$7:this.$7,scopes:this.scopeStack.length,privateNames:this.privateNameStack.length,labels:this.labels,labelCount:this.labels.length,strict:this.strict,yieldPos:this.yieldPos,awaitPos:this.awaitPos,awaitIdentPos:this.awaitIdentPos,potentialArrowAt:this.potentialArrowAt,potentialArrowInForAwait:this.potentialArrowInForAwait}}$16(state){this.pos=state.pos,this.type=state.type,this.value=state.value,this.start=state.start,this.end=state.end,this.startLoc=state.startLoc,this.endLoc=state.endLoc,this.lastTokStart=state.lastTokStart,this.lastTokEnd=state.lastTokEnd,this.lastTokStartLoc=state.lastTokStartLoc,this.lastTokEndLoc=state.lastTokEndLoc,this.curLine=state.curLine,this.lineStart=state.lineStart,this.context=state.context,this.exprAllowed=state.exprAllowed,this.containsEsc=state.containsEsc,this.inType=state.inType,this.$4=state.$4,this.$5=state.$5,this.$7=state.$7,this.scopeStack.length=state.scopes,this.privateNameStack.length=state.privateNames,this.labels=state.labels,this.labels.length=state.labelCount,this.strict=state.strict,this.yieldPos=state.yieldPos,this.awaitPos=state.awaitPos,this.awaitIdentPos=state.awaitIdentPos,this.potentialArrowAt=state.potentialArrowAt,this.potentialArrowInForAwait=state.potentialArrowInForAwait}raise(pos,message){if(this.$n>0)throw SPECULATION_FAILED;return super.raise(pos,message)}$1y(pos,message){try{super.raise(pos,message)}catch(error){if(error instanceof SyntaxError)error.$1z=!0;throw error}throw Error("unreachable")}$g(fn,lookahead=!1){let state=this.$15();this.$n++;try{let result=fn();if(lookahead||result===void 0)this.$16(state);return result}catch(error){if(!(error instanceof SyntaxError)||!lookahead&&error.$1z)throw error;this.$16(state);return}finally{this.$n--}}$v(fn){return this.$g(fn,!0)===!0}$17(node){if(node.end=this.lastTokEnd,this.options.locations)node.loc.end=this.lastTokEndLoc}$q(node,from){if(node.start=from.start,this.options.locations)node.loc.start=from.loc.start}$6(returnType=!1){let node=this.startNode();return node.typeAnnotation=this.$a(()=>(this.next(),returnType?this.$20():this.$0())),this.finishNode(node,"TSTypeAnnotation")}$h(node,optional){if(optional&&this.eat(tt.question))node.optional=!0,this.$17(node);if(this.type===tt.colon)node.typeAnnotation=this.$6(),this.$17(node);return node}$20(){if(this.type!==tt.name&&this.type!==tt._this)return this.$0();if(this.isContextual("asserts")&&this.$b()&&isIdentifierStart(this.$2())){let node=this.startNode();if(this.next(),node.parameterName=this.type===tt._this?this.$w():this.parseIdent(),this.isContextual("is")&&!this.hasPrecedingLineBreak())return this.$x(node,!0);return node.asserts=!0,node.typeAnnotation=null,this.finishNode(node,"TSTypePredicate")}if(this.$3()==="is"&&this.$b()){let node=this.startNode();return node.parameterName=this.type===tt._this?this.$w():this.parseIdent(!0),this.$x(node,!1)}return this.$0()}$x(node,asserts){this.next();let annotation=this.startNode();return annotation.typeAnnotation=this.$0(),node.typeAnnotation=this.finishNode(annotation,"TSTypeAnnotation"),node.asserts=asserts,this.finishNode(node,"TSTypePredicate")}$w(){let node=this.startNode();return this.next(),this.finishNode(node,"TSThisType")}parseWholeType(){this.inType=!0,this.nextToken();let type=this.$0();if(this.type!==tt.eof)this.unexpected();return type}$0(){let type=this.$18();if(this.$4||this.type!==tt._extends||this.hasPrecedingLineBreak())return type;let node=this.startNodeAt(type.start,type.loc?.start);return this.next(),node.checkType=type,node.extendsType=this.$i(!0,()=>this.$18()),this.expect(tt.question),node.trueType=this.$i(!1,()=>this.$0()),this.expect(tt.colon),node.falseType=this.$i(!1,()=>this.$0()),this.finishNode(node,"TSConditionalType")}$i(disallow,fn){let old=this.$4;this.$4=disallow;let result=fn();return this.$4=old,result}$18(){if(this.$21())return this.$19("TSFunctionType");if(this.type===tt._new||this.isContextual("abstract")&&this.$3()==="new")return this.$19("TSConstructorType");return this.$1a("TSUnionType",tt.bitwiseOR,()=>this.$1a("TSIntersectionType",tt.bitwiseAND,()=>this.$1b()))}$19(type){let node=this.startNode();if(type==="TSConstructorType"){if(node.abstract=this.isContextual("abstract"),node.abstract)this.next();this.next()}return this.$i(!1,()=>this.$r(node,tt.arrow)),this.finishNode(node,type)}$r(node,returnToken){if(this.$1())node.typeParameters=this.$8();if(this.expect(tt.parenL),node.parameters=this.parseBindingList(tt.parenR,!1,!0),this.type===returnToken)node.typeAnnotation=this.$6(!0);else if(returnToken===tt.arrow)this.unexpected()}$21(){if(this.$1())return!0;if(this.type!==tt.parenL)return!1;return this.$v(()=>{if(this.next(),this.type===tt.parenR||this.type===tt.ellipsis)return!0;if(this.type===tt.name||this.type===tt._this)this.next();else if(this.type===tt.braceL||this.type===tt.bracketL)this.parseBindingAtom();else return!1;let type=this.type;if(type===tt.colon||type===tt.comma||type===tt.question||type===tt.eq)return!0;if(type!==tt.parenR)return!1;return this.next(),this.type===tt.arrow})}$1a(type,operator,parseConstituent){let node=this.startNode(),hasLeadingOperator=this.eat(operator),types=[];do types.push(parseConstituent());while(this.eat(operator));if(types.length===1&&!hasLeadingOperator)return types[0];return node.types=types,this.finishNode(node,type)}$1b(){if(this.type===tt.name&&!this.containsEsc){let value=this.value;if(value==="keyof"||value==="unique"||value==="readonly"){let node=this.startNode();return this.next(),node.operator=value,node.typeAnnotation=this.$1b(),this.finishNode(node,"TSTypeOperator")}if(value==="infer"){let node=this.startNode();this.next();let parameter=this.startNode();parameter.name=this.$y();let constraint=this.$g(()=>this.$22());if(constraint)parameter.constraint=constraint;return node.typeParameter=this.finishNode(parameter,"TSTypeParameter"),this.finishNode(node,"TSInferType")}}return this.$i(!1,()=>this.$23())}$22(){if(!this.eat(tt._extends))return;let constraint=this.$i(!0,()=>this.$0());return this.$4||this.type!==tt.question?constraint:void 0}$y(){if(this.type!==tt.name&&!this.type.keyword)this.unexpected();let name=this.type===tt.name?this.value:this.type.keyword;return this.next(),name}$23(){let type=this.$24();while(!this.hasPrecedingLineBreak()&&this.eat(tt.bracketL)){let node=this.startNodeAt(type.start,type.loc?.start);if(this.eat(tt.bracketR))node.elementType=type,type=this.finishNode(node,"TSArrayType");else node.objectType=type,node.indexType=this.$0(),this.expect(tt.bracketR),type=this.finishNode(node,"TSIndexedAccessType")}return type}$24(){switch(this.type){case tt.name:case tt._void:case tt._null:{let keyword=KEYWORD_TYPES.get(this.value);if(keyword&&(this.type!==tt.name||!this.containsEsc&&this.$2()!==CHAR_DOT)){let node=this.startNode();return this.next(),this.finishNode(node,keyword)}return this.$1c()}case tt.string:case tt.num:case tt._true:case tt._false:{let node=this.startNode();return node.literal=this.parseExprAtom(),this.finishNode(node,"TSLiteralType")}case tt.plusMin:{if(this.value!=="-")break;let node=this.startNode(),unary=this.startNode();if(this.next(),this.type!==tt.num)this.unexpected();return unary.operator="-",unary.prefix=!0,unary.argument=this.parseExprAtom(),node.literal=this.finishNode(unary,"UnaryExpression"),this.finishNode(node,"TSLiteralType")}case tt.backQuote:return this.$25();case tt._this:{let thisType=this.$w();if(this.isContextual("is")&&!this.hasPrecedingLineBreak()){let node=this.startNodeAt(thisType.start,thisType.loc?.start);return node.parameterName=thisType,this.$x(node,!1)}return thisType}case tt._typeof:return this.$26();case tt._import:return this.$1d();case tt.braceL:return this.$27()?this.$28():this.$29();case tt.bracketL:return this.$2a();case tt.parenL:{let node=this.startNode();return this.next(),node.typeAnnotation=this.$0(),this.expect(tt.parenR),this.finishNode(node,"TSParenthesizedType")}default:if(this.type.keyword)return this.$1c()}return this.unexpected()}$1c(){let node=this.startNode();if(node.typeName=this.$j(),!this.hasPrecedingLineBreak()&&this.$1())node.typeArguments=this.$e();return this.finishNode(node,"TSTypeReference")}$j(){let entity=this.parseIdent(!0);while(this.eat(tt.dot)){let node=this.startNodeAt(entity.start,entity.loc?.start);node.left=entity,node.right=this.parseIdent(!0),entity=this.finishNode(node,"TSQualifiedName")}return entity}$26(){let node=this.startNode();if(this.next(),node.exprName=this.type===tt._import?this.$1d():this.$j(),!this.hasPrecedingLineBreak()&&this.$1())node.typeArguments=this.$e();return this.finishNode(node,"TSTypeQuery")}$1d(){let node=this.startNode();if(this.next(),node.argument=this.$1e(),this.eat(tt.dot))node.qualifier=this.$j();if(this.$1())node.typeArguments=this.$e();return this.finishNode(node,"TSImportType")}$z(){if(this.type!==tt.string)this.unexpected();return this.parseExprAtom()}$1e(){this.expect(tt.parenL);let string=this.$z();return this.expect(tt.parenR),string}$25(){let node=this.startNode(),literal=this.startNode();this.next(),literal.expressions=[];let element=this.parseTemplateElement({isTagged:!1});literal.quasis=[element];while(!element.tail){if(this.type===tt.eof)this.raise(this.pos,"Unterminated template literal");this.expect(tt.dollarBraceL),literal.expressions.push(this.$0()),this.expect(tt.braceR),element=this.parseTemplateElement({isTagged:!1}),literal.quasis.push(element)}return this.next(),node.literal=this.finishNode(literal,"TemplateLiteral"),this.finishNode(node,"TSLiteralType")}$27(){return this.$v(()=>{if(this.next(),this.type===tt.plusMin)return this.next(),this.isContextual("readonly");if(this.isContextual("readonly"))this.next();if(this.type!==tt.bracketL)return!1;if(this.next(),this.type!==tt.name)return!1;return this.next(),this.type===tt._in})}$28(){let node=this.startNode();if(this.expect(tt.braceL),this.type===tt.plusMin)node.readonly=this.value,this.next(),this.expectContextual("readonly");else if(this.eatContextual("readonly"))node.readonly=!0;this.expect(tt.bracketL);let parameter=this.startNode();if(parameter.name=this.$y(),this.expect(tt._in),parameter.constraint=this.$0(),node.typeParameter=this.finishNode(parameter,"TSTypeParameter"),node.nameType=this.eatContextual("as")?this.$0():null,this.expect(tt.bracketR),this.type===tt.plusMin)node.optional=this.value,this.next(),this.expect(tt.question);else if(this.eat(tt.question))node.optional=!0;if(this.eat(tt.colon))node.typeAnnotation=this.$0();return this.semicolon(),this.expect(tt.braceR),this.finishNode(node,"TSMappedType")}$29(){let node=this.startNode();return node.members=this.$1f(),this.finishNode(node,"TSTypeLiteral")}$1f(){this.expect(tt.braceL);let members=[];while(!this.eat(tt.braceR))members.push(this.$2b());return members}$2b(){let node=this.startNode(),type="TSPropertySignature",next=this.type===tt._new?this.$2():-1;if(this.type===tt.parenL||this.$1())type="TSCallSignatureDeclaration",this.$r(node,tt.colon);else if(next===CHAR_PAREN_L||next===CHAR_LT)type="TSConstructSignatureDeclaration",this.next(),this.$r(node,tt.colon);else{let newKey=this.type===tt._new?this.parseIdent(!0):null;if(this.isContextual("readonly")&&this.$s(!0))this.next(),node.readonly=!0;if(this.type===tt.bracketL&&this.$1g())return this.$1h(node);let kind="method";if(newKey)node.key=newKey;else{if((this.isContextual("get")||this.isContextual("set"))&&this.$s(!1))kind=this.value,this.next();this.parsePropertyName(node)}if(this.eat(tt.question))node.optional=!0;if(this.type===tt.parenL||this.$1()){if(type="TSMethodSignature",kind!=="method")node.kind=kind;this.$r(node,tt.colon),node.kind=kind}else if(this.type===tt.colon)node.typeAnnotation=this.$6()}return this.$1i(),this.finishNode(node,type)}$1i(){if(!this.eat(tt.comma))this.semicolon()}$1g(){return this.$v(()=>{if(this.next(),this.type!==tt.name)return!1;return this.next(),this.type===tt.colon})}$1h(node){if(this.expect(tt.bracketL),node.parameters=[this.$h(this.parseIdent(),!1)],this.expect(tt.bracketR),this.type===tt.colon)node.typeAnnotation=this.$6();return this.$1i(),this.finishNode(node,"TSIndexSignature")}$2a(){let node=this.startNode();this.expect(tt.bracketL),node.elementTypes=[];while(!this.eat(tt.bracketR))if(node.elementTypes.push(this.$2c()),this.type!==tt.bracketR)this.expect(tt.comma);return this.finishNode(node,"TSTupleType")}$2c(){let start=this.start,startLoc=this.startLoc,rest=this.eat(tt.ellipsis),element;if((this.type===tt.name||this.type.keyword)&&this.$2d()){let node=this.startNode();node.label=this.parseIdent(!0),node.optional=this.eat(tt.question),this.expect(tt.colon),node.elementType=this.$0(),element=this.finishNode(node,"TSNamedTupleMember")}else if(element=this.$0(),this.eat(tt.question)){let node=this.startNodeAt(element.start,element.loc?.start);node.typeAnnotation=element,element=this.finishNode(node,"TSOptionalType")}if(rest){let node=this.startNodeAt(start,startLoc);node.typeAnnotation=element,element=this.finishNode(node,"TSRestType")}return element}$2d(){let at=this.$d();if(this.input.charCodeAt(at)===63)at=this.$d(at+1);return this.input.charCodeAt(at)===CHAR_COLON}$8(){return this.$a(()=>{let node=this.startNode();this.next(),node.params=[];while(!this.$c()){let parameter=this.startNode();while((this.type===tt._const||this.type===tt._in||this.isContextual("out"))&&isIdentifierStart(this.$2()))parameter[this.value]=!0,this.next();if(parameter.name=this.$y(),this.eat(tt._extends))parameter.constraint=this.$0();if(this.eat(tt.eq))parameter.default=this.$0();if(node.params.push(this.finishNode(parameter,"TSTypeParameter")),!this.$c()){if(this.expect(tt.comma),this.$c())node.extra={trailingComma:this.lastTokStart}}}if(this.next(),node.params.length===0)this.$1y(this.start,"Type parameter list cannot be empty.");return this.finishNode(node,"TSTypeParameterDeclaration")})}$e(){return this.$a(()=>{let node=this.startNode();this.next(),node.params=[];while(!this.$c())if(node.params.push(this.$0()),!this.$c())this.expect(tt.comma);if(node.params.length===0)this.unexpected();return this.next(),this.finishNode(node,"TSTypeParameterInstantiation")})}$1j(){let list=[];do{let node=this.startNode();if(node.expression=this.$j(),this.$1())node.typeParameters=this.$e();list.push(this.finishNode(node,"TSExpressionWithTypeArguments"))}while(this.eat(tt.comma));return list}$1k(exported=!1){if(this.type!==tt.name||this.containsEsc){if(this.type===tt._const&&this.$3()==="enum")return this.$10(this.startNode());return}if(!this.$2e(this.value))return;if(this.value==="declare")return this.$2f(exported);return this.$1l(this.startNode(),this.value)}$2e(word){switch(word){case"interface":case"type":case"namespace":return this.$14();case"enum":return isIdentifierStart(this.$2());case"abstract":return this.$b()&&this.$3()==="class";case"module":{let next=this.$2();return this.$b()&&(next===CHAR_DQUOTE||next===CHAR_SQUOTE||isIdentifierStart(next))}case"declare":return this.$b()&&DECLARE_TARGETS.has(this.$3());case"global":return this.$b()&&this.$2()===CHAR_BRACE_L}return!1}$1l(node,word){switch(word){case"interface":return this.$1m(node);case"type":return this.$2g(node);case"enum":return this.$10(node);case"abstract":return this.$1n(node,!0);case"global":return node.global=!0,node.id=this.parseIdent(),node.body=this.$11(),this.finishNode(node,"TSModuleDeclaration")}return this.$2h(node)}$2f(exported){let old=this.$5;this.$5=!0;let node=this.startNode();this.next();let word=this.value;if(word==="const"&&this.$3()==="enum")node.const=!0;if(!exported&&DECLARE_FIRST.has(word))node.declare=!0;let declaration;if(node.const)declaration=this.$10(node);else if(word==="var"||word==="let"||word==="const")declaration=this.parseVarStatement(node,word,!0);else if(word==="function")this.next(),declaration=this.parseFunction(node,FUNC_STATEMENT,!1,!1);else if(word==="class")declaration=this.parseClass(node,!0);else declaration=this.$1l(node,word);return declaration.declare=!0,this.$5=old,declaration}$1n(node,isStatement){return this.next(),node.abstract=!0,this.parseClass(node,isStatement)}$1m(node){if(this.next(),node.id=this.parseIdent(),this.checkLValSimple(node.id,BIND_TS_INTERFACE),this.$1())node.typeParameters=this.$8();return this.$a(()=>{if(this.eat(tt._extends))node.extends=this.$1j();let body=this.startNode();body.body=this.$1f(),node.body=this.finishNode(body,"TSInterfaceBody")}),this.finishNode(node,"TSInterfaceDeclaration")}$2g(node){if(this.next(),node.id=this.parseIdent(),this.checkLValSimple(node.id,BIND_TS_TYPE),this.$1())node.typeParameters=this.$8();return node.typeAnnotation=this.$a(()=>(this.expect(tt.eq),this.$0())),this.semicolon(),this.finishNode(node,"TSTypeAliasDeclaration")}$10(node){if(this.type===tt._const)node.const=!0,this.next();this.next(),node.id=this.parseIdent(),this.checkLValSimple(node.id,BIND_TS_ENUM),this.expect(tt.braceL),node.members=[];while(!this.eat(tt.braceR)){let member=this.startNode();if(member.id=this.type===tt.string?this.parseExprAtom():this.parseIdent(!0),this.eat(tt.eq))member.initializer=this.parseMaybeAssign();if(node.members.push(this.finishNode(member,"TSEnumMember")),this.type!==tt.braceR)this.expect(tt.comma)}return this.finishNode(node,"TSEnumDeclaration")}$2h(node){if(this.next(),this.type===tt.string){if(node.id=this.parseExprAtom(),this.type===tt.braceL)node.body=this.$11();else this.semicolon();return this.finishNode(node,"TSModuleDeclaration")}return node.id=this.parseIdent(),this.checkLValSimple(node.id,BIND_TS_NAMESPACE),this.$1o(node)}$1o(node){if(this.eat(tt.dot)){let inner=this.startNode();inner.id=this.parseIdent(),node.body=this.$1o(inner)}else node.body=this.$11();return this.finishNode(node,"TSModuleDeclaration")}$11(){this.enterScope(SCOPE_CLASS_STATIC_BLOCK);let node=this.startNode();this.enterScope(0),this.expect(tt.braceL),node.body=[];while(!this.eat(tt.braceR))node.body.push(this.parseStatement(null,!0));return this.exitScope(),this.exitScope(),this.finishNode(node,"TSModuleBlock")}$1p(node,isExport){if(node.isExport=isExport,node.id=this.parseIdent(),this.checkLValSimple(node.id,BIND_LEXICAL),this.expect(tt.eq),this.isContextual("require")&&this.$2()===CHAR_PAREN_L){let reference=this.startNode();this.next(),reference.expression=this.$1e(),node.moduleReference=this.finishNode(reference,"TSExternalModuleReference")}else node.moduleReference=this.$j();return this.semicolon(),this.finishNode(node,"TSImportEqualsDeclaration")}$2i(){let at=this.$d();if(this.input.charCodeAt(at)!==CHAR_EQ)return!1;let after=this.input.charCodeAt(at+1);return after!==CHAR_EQ&&after!==62}parseStatement(context,topLevel,exports){if(this.type===atType)this.$1q(!0);let declaration=this.$1k();if(declaration)return declaration;return super.parseStatement(context,topLevel,exports)}parseVarStatement(node,kind,allowMissingInitializer){return super.parseVarStatement(node,kind,allowMissingInitializer||this.$5)}parseVarId(decl,kind){if(super.parseVarId(decl,kind),decl.id.type==="Identifier"&&this.$u()&&!this.hasPrecedingLineBreak())this.next(),decl.definite=!0;this.$h(decl.id,!1)}parseCatchClauseParam(){let param=this.$h(this.parseBindingAtom(),!1),simple=param.type==="Identifier";return this.enterScope(simple?SCOPE_SIMPLE_CATCH:0),this.checkLValPattern(param,simple?BIND_SIMPLE_CATCH:BIND_LEXICAL),this.expect(tt.parenR),param}parseImport(node){if(this.next(),node.importKind="value",this.type===tt.string)node.specifiers=[],node.source=this.parseExprAtom();else{if(this.isContextual("type")){let next=this.$2();if(next===CHAR_BRACE_L||next===CHAR_STAR||isIdentifierStart(next)&&this.$3()!=="from")node.importKind="type",this.next()}if(this.type===tt.name&&this.$2i())return this.$1p(node,!1);node.specifiers=this.parseImportSpecifiers(),this.expectContextual("from"),node.source=this.$z()}return this.$1r(node),this.semicolon(),this.finishNode(node,"ImportDeclaration")}parseWithClause(){if(this.isContextual("assert")&&!this.hasPrecedingLineBreak())this.type=tt._with;return this.type===tt._with?super.parseWithClause():void 0}$1r(node){let attributes=this.parseWithClause();if(attributes)node.attributes=attributes}parseImportSpecifier(){return this.$1s("importKind",()=>super.parseImportSpecifier())}parseExportSpecifier(exports){return this.$1s("exportKind",()=>super.parseExportSpecifier(exports))}$1s(kindKey,parse){let next=this.isContextual("type")?this.$2():-1;if(next===CHAR_DQUOTE||next===CHAR_SQUOTE||isIdentifierStart(next)&&this.$3()!=="as"){let modifier=this.startNode();this.next();let node=parse();return this.$q(node,modifier),node[kindKey]="type",node}let node=parse();return node[kindKey]="value",node}parseExport(node,exports){if(this.next(),this.eat(tt._import)){if(node.importKind="value",this.isContextual("type")&&isIdentifierStart(this.$2())&&this.$3()!=="from")node.importKind="type",this.next();return this.$1p(node,!0)}if(this.eat(tt.eq))return node.expression=this.parseExpression(),this.semicolon(),this.finishNode(node,"TSExportAssignment");if(this.eatContextual("as"))return this.expectContextual("namespace"),node.id=this.parseIdent(),this.semicolon(),this.finishNode(node,"TSNamespaceExportDeclaration");if(node.exportKind="value",this.isContextual("type")){let next=this.$2();if(next===CHAR_BRACE_L||next===CHAR_STAR)node.exportKind="type",this.next()}if(this.eat(tt.star))return this.parseExportAllDeclaration(node,exports);if(this.eat(tt._default)){if(this.isContextual("interface")&&this.$14())node.declaration=this.$1m(this.startNode());else if(this.isContextual("abstract")&&this.$3()==="class")node.declaration=this.$1n(this.startNode(),"nullableID");else node.declaration=this.parseExportDefaultDeclaration();return this.finishNode(node,"ExportDefaultDeclaration")}let isDeclare=this.isContextual("declare"),declaration=this.$1k(!0);if(declaration||this.shouldParseExportStatement()){if(node.declaration=declaration??this.parseStatement(null),isDeclare||node.declaration.type==="TSInterfaceDeclaration"||node.declaration.type==="TSTypeAliasDeclaration")node.exportKind="type";return node.specifiers=[],node.source=null,this.finishNode(node,"ExportNamedDeclaration")}if(node.declaration=null,node.specifiers=this.parseExportSpecifiers(exports),this.eatContextual("from"))node.source=this.$z(),this.$1r(node);else{for(let spec of node.specifiers)if(this.checkUnreserved(spec.local),this.checkLocalExport(spec.local),spec.local.type==="Literal")this.raise(spec.local.start,"A string literal cannot be used as an exported binding without `from`.");node.source=null}return this.semicolon(),this.finishNode(node,"ExportNamedDeclaration")}parseFunction(node,statement,allowExpressionBody,isAsync,forInit){let isDeclaration=statement&FUNC_STATEMENT;if(isDeclaration)this.$f=node,this.$o=node.start;super.parseFunction(node,statement,allowExpressionBody,isAsync,forInit),this.$f=null;let bodiless=!node.body;if(bodiless)node.type="TSDeclareFunction";if(isDeclaration&&node.id){if(bodiless){if(this.$5&&this.currentScope().flags&SCOPE_TOP)this.declareName(node.id.name,BIND_FLAGS_TS_EXPORT_ONLY,node.id.start);this.checkLValSimple(node.id,BIND_NONE)}else if(!(statement&FUNC_HANGING_STATEMENT)){let bindingType=BIND_FUNCTION;if(this.strict||node.generator||node.async)bindingType=this.treatFunctionsAsVar?BIND_VAR:BIND_LEXICAL;this.checkLValSimple(node.id,bindingType)}}return node}parseFunctionParams(node){if(this.$1())node.typeParameters=this.$8();if(super.parseFunctionParams(node),this.type===tt.colon)node.returnType=this.$6(!0)}parseFunctionBody(node,isArrowFunction,isMethod,forInit){if(isMethod&&this.type===tt.colon)node.returnType=this.$6(!0);if(isArrowFunction||this.type===tt.braceL||node.start!==this.$o){super.parseFunctionBody(node,isArrowFunction,isMethod,forInit);return}this.semicolon(),this.exitScope()}parseMethod(isGenerator,isAsync,allowDirectSuper){let typeParameters=this.$k;this.$k=null;let node=super.parseMethod(isGenerator,isAsync,allowDirectSuper);if(!node.body)node.type="TSDeclareMethod";if(typeParameters)node.typeParameters=typeParameters;return node}parseBindingList(close,allowEmpty,allowTrailingComma,allowModifiers){let modifiers=allowModifiers===!0||this.$l;return this.$l=!1,super.parseBindingList(close,allowEmpty,allowTrailingComma,modifiers)}$s(allowLineBreak){if(!allowLineBreak&&!this.$b())return!1;let next=this.$2();return next===CHAR_BRACKET_L||next===CHAR_BRACE_L||next===CHAR_STAR||next===CHAR_DOT||next===CHAR_HASH||next===CHAR_DQUOTE||next===CHAR_SQUOTE||next>=48&&next<=57||isIdentifierStart(next)}parseAssignableListItem(allowModifiers){let decorators=this.$12(),start=this.start,startLoc=this.startLoc,accessibility,readonly=!1,override=!1;if(allowModifiers)while(this.type===tt.name&&PARAMETER_MODIFIERS.has(this.value)&&!this.containsEsc&&this.$s(!1)){if(this.value==="readonly")readonly=!0;else if(this.value==="override")override=!0;else accessibility=this.value;this.next()}let left;if(this.type===tt._this)left=this.startNode(),left.name="this",this.next(),this.finishNode(left,"Identifier");else left=this.parseBindingAtom();let element=this.type===tt.eq?this.parseMaybeDefault(start,startLoc,left):this.parseMaybeDefault(left.start,left.loc?.start,this.$h(left,!0));if(decorators.length>0)element.decorators=decorators;if(!accessibility&&!readonly&&!override)return element;let node=this.startNodeAt(start,startLoc);if(accessibility)node.accessibility=accessibility;if(readonly)node.readonly=!0;if(override)node.override=!0;return node.parameter=element,this.finishNode(node,"TSParameterProperty")}parseBindingListItem(param){if(param.type==="RestElement")this.$h(param,!0);return param}checkLValSimple(expr,bindingType,checkClashes){if(this.$f&&expr===this.$f.id){this.$f=null;return}if(!bindingType&&TS_EXPRESSION_WRAPPERS.has(expr.type)){this.checkLValSimple(expr.expression,bindingType,checkClashes);return}switch(expr.type){case"TSParameterProperty":this.checkLValInnerPattern(expr.parameter,bindingType,checkClashes);return;case"Identifier":if(expr.name==="this")return}super.checkLValSimple(expr,bindingType,checkClashes)}toAssignable(node,isBinding,refDestructuringErrors){if(node&&!isBinding&&TS_EXPRESSION_WRAPPERS.has(node.type))return node;return super.toAssignable(node,isBinding,refDestructuringErrors)}declareName(name,bindingType,pos){let scope=this.currentScope();if(bindingType&BIND_FLAGS_TS_EXPORT_ONLY){this.$1t(scope,name),scope.$1u??=[],scope.$1u.push(name);return}if(bindingType===BIND_TS_TYPE||bindingType===BIND_TS_INTERFACE){if(scope.$13??=[],bindingType===BIND_TS_TYPE&&hasName(scope.$13,name))this.raise(pos,`type '${name}' has already been declared.`);scope.$13.push(name),this.$1t(scope,name);return}if(bindingType&BIND_FLAGS_TS_ENUM){if(scope.$1v??=[],hasName(scope.$1v,name))return;super.declareName(name,BIND_LEXICAL,pos),scope.$1v.push(name);return}super.declareName(name,bindingType,pos)}$1t(scope,name){if(this.inModule&&scope.flags&SCOPE_TOP)delete this.undefinedExports[name]}checkLocalExport(id){for(let i=this.scopeStack.length-1;i>=0;i--){let scope=this.scopeStack[i];if(hasName(scope.$13,id.name)||hasName(scope.$1u,id.name))return}super.checkLocalExport(id)}checkExport(){}raiseRecoverable(pos,message){if(message==="Duplicate constructor in the same class")return;super.raiseRecoverable(pos,message)}$12(){let decorators=[];while(this.type===atType)decorators.push(this.$1w());return decorators}$1q(allowExport){let pending=this.$9[this.$9.length-1];while(this.type===atType)pending.push(this.$1w());if(this.type===tt._export){if(!allowExport)this.unexpected()}else if(this.type!==tt._class&&!((this.isContextual("abstract")||this.isContextual("declare"))&&this.$3()==="class"))this.raise(this.start,"Leading decorators must be attached to a class declaration.")}$1w(){let node=this.startNode();this.next(),this.$9.push([]);let startPos=this.start,startLoc=this.startLoc,expression;if(this.type===tt.parenL){if(this.next(),expression=this.parseExpression(),this.expect(tt.parenR),this.options.preserveParens){let paren=this.startNodeAt(startPos,startLoc);paren.expression=expression,expression=this.finishNode(paren,"ParenthesizedExpression")}}else{expression=this.parseIdent(!1);while(this.eat(tt.dot)){let member=this.startNodeAt(startPos,startLoc);member.object=expression,member.property=this.parseIdent(!0),member.computed=!1,expression=this.finishNode(member,"MemberExpression")}}let typeArguments=this.$p()?this.$e():void 0;if(this.eat(tt.parenL)){let call=this.startNodeAt(expression.start,expression.loc?.start);if(call.callee=expression,call.arguments=this.parseExprList(tt.parenR,!1,!1),typeArguments)call.typeArguments=typeArguments;expression=this.finishNode(call,"CallExpression")}else if(typeArguments){let instantiation=this.startNodeAt(expression.start,expression.loc?.start);instantiation.expression=expression,instantiation.typeArguments=typeArguments,expression=this.finishNode(instantiation,"TSInstantiationExpression")}return node.expression=expression,this.$9.pop(),this.finishNode(node,"Decorator")}shouldParseExportStatement(){return this.type===atType||super.shouldParseExportStatement()}parseExprAtom(refDestructuringErrors,forInit,forNew){if(this.type===atType)this.$1q(!1);return super.parseExprAtom(refDestructuringErrors,forInit,forNew)}parseProperty(isPattern,refDestructuringErrors){if(isPattern||this.type!==atType)return super.parseProperty(isPattern,refDestructuringErrors);let decorators=this.$12(),property=super.parseProperty(isPattern,refDestructuringErrors);if(property.type==="SpreadElement")this.raise(property.start,"Decorators can't be used with SpreadElement");return property.decorators=decorators,property}parseClassId(node,isStatement){let index=this.$9.length-1,decorators=this.$9[index];if(decorators.length>0)node.decorators=decorators,this.$q(node,decorators[0]),this.$9[index]=[];if(!this.isContextual("implements")||isStatement===!0)super.parseClassId(node,isStatement);if(this.$1())node.typeParameters=this.$8()}parseClassSuper(node){if(super.parseClassSuper(node),node.superClass&&this.$1())node.superTypeParameters=this.$e();if(this.eatContextual("implements"))node.implements=this.$a(()=>this.$1j())}parseClassElement(constructorAllowsSuper){if(this.type===atType){let decorators=this.$12();if(this.type===tt.braceR)this.raise(this.start,"Decorators must be attached to a class element.");let element=this.parseClassElement(constructorAllowsSuper);return element.decorators=decorators,this.$q(element,decorators[0]),element}if(this.eat(tt.semi))return null;let node=this.startNode();while(this.type===tt.name&&CLASS_MODIFIERS.has(this.value)&&!this.containsEsc&&this.$s(this.value==="static")){let modifier=this.value;if(this.next(),modifier==="static"&&this.type===tt.braceL)return this.next(),this.parseClassStaticBlock(node),node;if(modifier==="public"||modifier==="private"||modifier==="protected")node.accessibility=modifier;else node[modifier]=!0}if(this.type===tt.bracketL&&this.$1g())return this.$1h(node);node.static??=!1;let keyName="",isGenerator=!1,isAsync=!1,kind="method";if(this.eatContextual("async"))if((this.isClassElementNameStart()||this.type===tt.star)&&!this.canInsertSemicolon())isAsync=!0;else keyName="async";if(!keyName&&this.eat(tt.star))isGenerator=!0;if(!keyName&&!isAsync&&!isGenerator){let lastValue=this.value;if(this.eatContextual("get")||this.eatContextual("set"))if(this.isClassElementNameStart())kind=lastValue;else keyName=lastValue}if(keyName)node.computed=!1,node.key=this.startNodeAt(this.lastTokStart,this.lastTokStartLoc),node.key.name=keyName,this.finishNode(node.key,"Identifier");else this.parseClassElementName(node);if(this.eat(tt.question))node.optional=!0;if(this.type===tt.parenL||this.$1()||kind!=="method"||isGenerator||isAsync){let key=node.key,isConstructor=!node.static&&!node.computed&&(key.type==="Identifier"&&key.name==="constructor"||key.type==="Literal"&&key.value==="constructor");if(node.kind=isConstructor?"constructor":kind,this.$1())node.typeParameters=this.$8();this.$l=isConstructor,this.$o=this.start,this.parseClassMethod(node,isGenerator,isAsync,isConstructor&&constructorAllowsSuper)}else{if(!node.optional&&this.$u())this.next(),node.definite=!0;if(this.type===tt.colon)node.typeAnnotation=this.$6();this.parseClassField(node)}return node}parseMaybeAssign(forInit,refDestructuringErrors,afterLeftParse){if(this.$p()){let arrow=this.$g(()=>{let typeParameters=this.$8(),expr=super.parseMaybeAssign(forInit,refDestructuringErrors,afterLeftParse);if(expr.type!=="ArrowFunctionExpression")return;return expr.typeParameters=typeParameters,this.$q(expr,typeParameters),expr});if(arrow)return arrow}return super.parseMaybeAssign(forInit,refDestructuringErrors,afterLeftParse)}parseMaybeUnary(refDestructuringErrors,sawUnary,incDec,forInit){if(this.$p()){let node=this.startNode();return node.typeAnnotation=this.$a(()=>{this.next();let type=this.$0();if(!this.$c())this.unexpected();return this.next(),type}),node.expression=this.parseMaybeUnary(null,!1,!1,forInit),this.finishNode(node,"TSTypeAssertion")}return super.parseMaybeUnary(refDestructuringErrors,sawUnary,incDec,forInit)}parseMaybeConditional(forInit,refDestructuringErrors){let startPos=this.start,startLoc=this.startLoc,expr=this.parseExprOps(forInit,refDestructuringErrors);if(this.checkExpressionErrors(refDestructuringErrors))return expr;if(this.type===tt.question&&!(expr.type==="ArrowFunctionExpression"&&expr.start===startPos)&&!this.$2j()){this.next();let node=this.startNodeAt(startPos,startLoc);return node.test=expr,node.consequent=this.parseMaybeAssign(),this.expect(tt.colon),node.alternate=this.parseMaybeAssign(forInit),this.finishNode(node,"ConditionalExpression")}return expr}$2j(){let at=this.$d(),next=this.input.charCodeAt(at);if(next===CHAR_COLON||next===CHAR_COMMA||next===CHAR_PAREN_R)return!0;return next===CHAR_EQ&&this.input.charCodeAt(at+1)!==CHAR_EQ}parseParenItem(item){return this.$h(item,!0)}$1x(){if(this.type!==tt.colon)return!0;let returnType=this.$g(()=>{let type=this.$6(!0);return this.type===tt.arrow&&!this.canInsertSemicolon()?type:void 0});if(!returnType)return!1;return this.$7=returnType,!0}shouldParseArrow(exprList){return this.$1x()&&super.shouldParseArrow(exprList)}shouldParseAsyncArrow(){return this.$1x()&&super.shouldParseAsyncArrow()}parseArrowExpression(node,params,isAsync,forInit){if(this.$7)node.returnType=this.$7,this.$7=null;return super.parseArrowExpression(node,params,isAsync,forInit)}parseExprList(close,allowTrailingComma,allowEmpty,refDestructuringErrors){if(!this.$m)return super.parseExprList(close,allowTrailingComma,allowEmpty,refDestructuringErrors);this.$m=!1;let elements=[],first=!0;while(!this.eat(close)){if(first)first=!1;else if(this.expect(tt.comma),allowTrailingComma&&this.afterTrailingComma(close))break;if(this.type===tt.ellipsis){let spread=this.parseSpread(refDestructuringErrors);if(this.eat(tt.question))spread.optional=!0;if(this.type===tt.colon)spread.typeAnnotation=this.$6();elements.push(spread)}else elements.push(this.parseMaybeAssign(!1,refDestructuringErrors,this.parseParenItem))}return elements}parseSubscript(base,startPos,startLoc,noCalls,maybeAsyncArrow,optionalChained,forInit){if(this.$u()&&!this.hasPrecedingLineBreak()){let node=this.startNodeAt(startPos,startLoc);return this.exprAllowed=!1,this.next(),node.expression=base,this.finishNode(node,"TSNonNullExpression")}if(maybeAsyncArrow&&this.$1()){let arrow=this.$g(()=>this.$2k(startPos,startLoc,forInit));if(arrow)return arrow}let optional=this.type===tt.questionDot&&this.$2()===CHAR_LT;if(this.$1()||optional||this.type===tt.bitShift&&this.value==="<<"){let typeArguments=this.$g(()=>{if(optional)this.next();this.$p();let args=this.$e();if(this.type===tt.parenL&&!noCalls)return args;if(this.type===tt.backQuote)return optional?void 0:args;if(optional)return;if(this.$c()||this.type===tt.bitShift||this.type.startsExpr&&this.type!==tt.parenL&&!this.hasPrecedingLineBreak())return;return args});if(typeArguments){let node=this.startNodeAt(startPos,startLoc);if(this.type===tt.parenL&&!noCalls){if(this.next(),node.callee=base,node.arguments=this.parseExprList(tt.parenR,!0,!1),node.typeArguments=typeArguments,optional)base.optional=!0;if(optional||optionalChained)node.optional=optional;return this.finishNode(node,"CallExpression")}if(this.type===tt.backQuote)return node.tag=base,node.quasi=this.parseTemplate({isTagged:!0}),node.typeArguments=typeArguments,this.finishNode(node,"TaggedTemplateExpression");return node.expression=base,node.typeArguments=typeArguments,this.finishNode(node,"TSInstantiationExpression")}}if(maybeAsyncArrow&&this.type===tt.parenL)this.$m=!0;return super.parseSubscript(base,startPos,startLoc,noCalls,maybeAsyncArrow,optionalChained,forInit)}$2k(startPos,startLoc,forInit){let node=this.startNodeAt(startPos,startLoc);if(node.typeParameters=this.$8(),this.expect(tt.parenL),node.params=this.parseBindingList(tt.parenR,!1,!0),this.type===tt.colon)node.returnType=this.$6(!0);if(this.type!==tt.arrow||this.canInsertSemicolon())return;return this.next(),this.parseArrowExpression(node,node.params,!0,forInit)}parseDynamicImport(node){if(this.next(),node.source=this.parseMaybeAssign(),this.eat(tt.comma)&&this.type!==tt.parenR)node.arguments=[this.parseExpression()];return this.expect(tt.parenR),this.finishNode(node,"ImportExpression")}parseNew(){let node=super.parseNew();if(node.callee?.type!=="TSInstantiationExpression")return node;let result=this.startNodeAt(node.start,node.loc?.start);return result.callee=node.callee.expression,result.typeArguments=node.callee.typeArguments,result.arguments=node.arguments,this.finishNodeAt(result,"NewExpression",node.end,node.loc?.end)}parseExprOp(left,leftStartPos,leftStartLoc,minPrec,forInit){if(tt._in.binop>minPrec&&this.type===tt.name&&(this.value==="as"||this.value==="satisfies")&&!this.containsEsc&&!this.hasPrecedingLineBreak()){let isSatisfies=this.value==="satisfies",node=this.startNodeAt(leftStartPos,leftStartLoc);return node.expression=left,node.typeAnnotation=this.$a(()=>{if(this.next(),!isSatisfies&&this.type===tt._const){let reference=this.startNode();return reference.typeName=this.parseIdent(!0),this.finishNode(reference,"TSTypeReference")}return this.$0()}),this.finishNode(node,isSatisfies?"TSSatisfiesExpression":"TSAsExpression"),this.parseExprOp(node,leftStartPos,leftStartLoc,minPrec,forInit)}return super.parseExprOp(left,leftStartPos,leftStartLoc,minPrec,forInit)}parseGetterSetter(prop){prop.kind=prop.key.name,super.parseGetterSetter(prop)}parsePropertyValue(prop,isPattern,isGenerator,isAsync,startPos,startLoc,refDestructuringErrors,containsEsc){if(!isPattern&&this.$1()){if(this.$k=this.$8(),this.type!==tt.parenL)this.unexpected();prop.kind="init"}return super.parsePropertyValue(prop,isPattern,isGenerator,isAsync,startPos,startLoc,refDestructuringErrors,containsEsc)}}return TSParser});
|
|
1
|
+
import{definePlugin,hasLineBreak,hasName}from"./shared-s46wfvhw.js";var SKIP_WHITESPACE=/(?:\s|\/\/.*|\/\*[\s\S]*?\*\/)*/g,KEYWORD_TYPES=new Map([["any","TSAnyKeyword"],["bigint","TSBigIntKeyword"],["boolean","TSBooleanKeyword"],["never","TSNeverKeyword"],["null","TSNullKeyword"],["number","TSNumberKeyword"],["object","TSObjectKeyword"],["string","TSStringKeyword"],["symbol","TSSymbolKeyword"],["undefined","TSUndefinedKeyword"],["unknown","TSUnknownKeyword"],["void","TSVoidKeyword"]]),CLASS_MODIFIERS=new Set("public private protected readonly declare abstract override static accessor".split(" ")),PARAMETER_MODIFIERS=new Set("public private protected readonly override".split(" ")),DECLARE_TARGETS=new Set("var let const function class abstract enum interface type namespace module global".split(" ")),DECLARE_FIRST=new Set("var let const function class interface enum".split(" ")),TS_EXPRESSION_WRAPPERS=new Set(["TSAsExpression","TSSatisfiesExpression","TSNonNullExpression","TSTypeAssertion"]),SCOPE_TOP=1,SCOPE_SIMPLE_CATCH=32,SCOPE_CLASS_STATIC_BLOCK=256,BIND_NONE=0,BIND_VAR=1,BIND_LEXICAL=2,BIND_FUNCTION=3,BIND_SIMPLE_CATCH=4,BIND_TS_TYPE=6,BIND_TS_INTERFACE=7,BIND_FLAGS_TS_ENUM=256,BIND_FLAGS_TS_EXPORT_ONLY=1024,BIND_TS_NAMESPACE=8|BIND_FLAGS_TS_EXPORT_ONLY,BIND_TS_ENUM=BIND_LEXICAL|BIND_FLAGS_TS_ENUM,FUNC_STATEMENT=1,FUNC_HANGING_STATEMENT=2,CHAR_PAREN_L=40,CHAR_PAREN_R=41,CHAR_COMMA=44,CHAR_DOT=46,CHAR_COLON=58,CHAR_EQ=61,CHAR_LT=60,CHAR_BRACE_L=123,CHAR_BRACKET_L=91,CHAR_STAR=42,CHAR_HASH=35,CHAR_DQUOTE=34,CHAR_SQUOTE=39,SPECULATION_FAILED=SyntaxError("speculative parse failed"),tsPlugin=definePlugin((Base)=>{let{tokTypes:tt,keywordTypes,isIdentifierChar,isIdentifierStart}=Base.acorn,atType=new Base.acorn.TokenType("@");class TSParser extends Base{inType=!1;$4=!1;$5=!1;$7=null;$k=null;$l=!1;$m=!1;$f=null;$9=[[]];$n=0;$t=0;$o=-1;constructor(options,input,startPos){super(options,input,startPos);let onComment=this.options.onComment;if(typeof onComment==="function")this.options.onComment=(block,text,start,end,startLoc,endLoc)=>{if(start<this.$t)return;this.$t=end,onComment.call(this,block,text,start,end,startLoc,endLoc)}}reset(){this.inType=!1,this.$4=!1,this.$5=!1,this.$7=null,this.$k=null,this.$l=!1,this.$m=!1,this.$f=null,this.$9=[[]],this.$n=0,this.$t=0,this.$o=-1}getTokenFromCode(code){if(code===64)return++this.pos,this.finishToken(atType);return super.getTokenFromCode(code)}readToken_lt_gt(code){if(this.inType)return this.finishOp(tt.relational,1);return super.readToken_lt_gt(code)}$a(fn){let old=this.inType;this.inType=!0;let result=fn();if(this.inType=old,!old&&this.type===tt.relational)this.pos=this.start,this.nextToken();return result}$1(){return this.type===tt.relational&&this.value==="<"}$p(){if(this.type===tt.bitShift&&this.value==="<<")this.pos=this.start+1,this.finishToken(tt.relational,"<");return this.$1()}$c(){return this.type===tt.relational&&this.value===">"}$u(){return this.type===tt.prefix&&this.value==="!"}hasPrecedingLineBreak(){return hasLineBreak(this.input,this.lastTokEnd,this.start)}$d(from=this.pos){return SKIP_WHITESPACE.lastIndex=from,SKIP_WHITESPACE.exec(this.input),SKIP_WHITESPACE.lastIndex}$2(){return this.input.charCodeAt(this.$d())}$3(){let start=this.$d(),end=start;while(end<this.input.length&&isIdentifierChar(this.input.charCodeAt(end)))end++;return this.input.slice(start,end)}$b(){return!hasLineBreak(this.input,this.pos,this.$d())}$14(){return this.$b()&&isIdentifierStart(this.$2())&&!Object.hasOwn(keywordTypes,this.$3())}$15(){return{pos:this.pos,type:this.type,value:this.value,start:this.start,end:this.end,startLoc:this.startLoc,endLoc:this.endLoc,lastTokStart:this.lastTokStart,lastTokEnd:this.lastTokEnd,lastTokStartLoc:this.lastTokStartLoc,lastTokEndLoc:this.lastTokEndLoc,curLine:this.curLine,lineStart:this.lineStart,context:this.context.slice(),exprAllowed:this.exprAllowed,containsEsc:this.containsEsc,inType:this.inType,$4:this.$4,$5:this.$5,$7:this.$7,scopes:this.scopeStack.length,privateNames:this.privateNameStack.length,labels:this.labels,labelCount:this.labels.length,strict:this.strict,yieldPos:this.yieldPos,awaitPos:this.awaitPos,awaitIdentPos:this.awaitIdentPos,potentialArrowAt:this.potentialArrowAt,potentialArrowInForAwait:this.potentialArrowInForAwait}}$16(state){this.pos=state.pos,this.type=state.type,this.value=state.value,this.start=state.start,this.end=state.end,this.startLoc=state.startLoc,this.endLoc=state.endLoc,this.lastTokStart=state.lastTokStart,this.lastTokEnd=state.lastTokEnd,this.lastTokStartLoc=state.lastTokStartLoc,this.lastTokEndLoc=state.lastTokEndLoc,this.curLine=state.curLine,this.lineStart=state.lineStart,this.context=state.context,this.exprAllowed=state.exprAllowed,this.containsEsc=state.containsEsc,this.inType=state.inType,this.$4=state.$4,this.$5=state.$5,this.$7=state.$7,this.scopeStack.length=state.scopes,this.privateNameStack.length=state.privateNames,this.labels=state.labels,this.labels.length=state.labelCount,this.strict=state.strict,this.yieldPos=state.yieldPos,this.awaitPos=state.awaitPos,this.awaitIdentPos=state.awaitIdentPos,this.potentialArrowAt=state.potentialArrowAt,this.potentialArrowInForAwait=state.potentialArrowInForAwait}raise(pos,message){if(this.$n>0)throw SPECULATION_FAILED;return super.raise(pos,message)}$1y(pos,message){try{super.raise(pos,message)}catch(error){if(error instanceof SyntaxError)error.$1z=!0;throw error}throw Error("unreachable")}$g(fn,lookahead=!1){let state=this.$15();this.$n++;try{let result=fn();if(lookahead||result===void 0)this.$16(state);return result}catch(error){if(!(error instanceof SyntaxError)||!lookahead&&error.$1z)throw error;this.$16(state);return}finally{this.$n--}}$v(fn){return this.$g(fn,!0)===!0}$17(node){if(node.end=this.lastTokEnd,this.options.locations)node.loc.end=this.lastTokEndLoc}$q(node,from){if(node.start=from.start,this.options.locations)node.loc.start=from.loc.start}$6(returnType=!1){let node=this.startNode();return node.typeAnnotation=this.$a(()=>(this.next(),returnType?this.$20():this.$0())),this.finishNode(node,"TSTypeAnnotation")}$h(node,optional){if(optional&&this.eat(tt.question))node.optional=!0,this.$17(node);if(this.type===tt.colon)node.typeAnnotation=this.$6(),this.$17(node);return node}$20(){if(this.type!==tt.name&&this.type!==tt._this)return this.$0();if(this.isContextual("asserts")&&this.$b()&&isIdentifierStart(this.$2())){let node=this.startNode();if(this.next(),node.parameterName=this.type===tt._this?this.$w():this.parseIdent(),this.isContextual("is")&&!this.hasPrecedingLineBreak())return this.$x(node,!0);return node.asserts=!0,node.typeAnnotation=null,this.finishNode(node,"TSTypePredicate")}if(this.$3()==="is"&&this.$b()){let node=this.startNode();return node.parameterName=this.type===tt._this?this.$w():this.parseIdent(!0),this.$x(node,!1)}return this.$0()}$x(node,asserts){this.next();let annotation=this.startNode();return annotation.typeAnnotation=this.$0(),node.typeAnnotation=this.finishNode(annotation,"TSTypeAnnotation"),node.asserts=asserts,this.finishNode(node,"TSTypePredicate")}$w(){let node=this.startNode();return this.next(),this.finishNode(node,"TSThisType")}parseWholeType(){this.inType=!0,this.nextToken();let type=this.$0();if(this.type!==tt.eof)this.unexpected();return type}$0(){let type=this.$18();if(this.$4||this.type!==tt._extends||this.hasPrecedingLineBreak())return type;let node=this.startNodeAt(type.start,type.loc?.start);return this.next(),node.checkType=type,node.extendsType=this.$i(!0,()=>this.$18()),this.expect(tt.question),node.trueType=this.$i(!1,()=>this.$0()),this.expect(tt.colon),node.falseType=this.$i(!1,()=>this.$0()),this.finishNode(node,"TSConditionalType")}$i(disallow,fn){let old=this.$4;this.$4=disallow;let result=fn();return this.$4=old,result}$18(){if(this.$21())return this.$19("TSFunctionType");if(this.type===tt._new||this.isContextual("abstract")&&this.$3()==="new")return this.$19("TSConstructorType");return this.$1a("TSUnionType",tt.bitwiseOR,()=>this.$1a("TSIntersectionType",tt.bitwiseAND,()=>this.$1b()))}$19(type){let node=this.startNode();if(type==="TSConstructorType"){if(node.abstract=this.isContextual("abstract"),node.abstract)this.next();this.next()}return this.$i(!1,()=>this.$r(node,tt.arrow)),this.finishNode(node,type)}$r(node,returnToken){if(this.$1())node.typeParameters=this.$8();if(this.expect(tt.parenL),node.parameters=this.parseBindingList(tt.parenR,!1,!0),this.type===returnToken)node.typeAnnotation=this.$6(!0);else if(returnToken===tt.arrow)this.unexpected()}$21(){if(this.$1())return!0;if(this.type!==tt.parenL)return!1;return this.$v(()=>{if(this.next(),this.type===tt.parenR||this.type===tt.ellipsis)return!0;if(this.type===tt.name||this.type===tt._this)this.next();else if(this.type===tt.braceL||this.type===tt.bracketL)this.parseBindingAtom();else return!1;let type=this.type;if(type===tt.colon||type===tt.comma||type===tt.question||type===tt.eq)return!0;if(type!==tt.parenR)return!1;return this.next(),this.type===tt.arrow})}$1a(type,operator,parseConstituent){let node=this.startNode(),hasLeadingOperator=this.eat(operator),types=[];do types.push(parseConstituent());while(this.eat(operator));if(types.length===1&&!hasLeadingOperator)return types[0];return node.types=types,this.finishNode(node,type)}$1b(){if(this.type===tt.name&&!this.containsEsc){let value=this.value;if(value==="keyof"||value==="unique"||value==="readonly"){let node=this.startNode();return this.next(),node.operator=value,node.typeAnnotation=this.$1b(),this.finishNode(node,"TSTypeOperator")}if(value==="infer"){let node=this.startNode();this.next();let parameter=this.startNode();parameter.name=this.$y();let constraint=this.$g(()=>this.$22());if(constraint)parameter.constraint=constraint;return node.typeParameter=this.finishNode(parameter,"TSTypeParameter"),this.finishNode(node,"TSInferType")}}return this.$i(!1,()=>this.$23())}$22(){if(!this.eat(tt._extends))return;let constraint=this.$i(!0,()=>this.$0());return this.$4||this.type!==tt.question?constraint:void 0}$y(){if(this.type!==tt.name&&!this.type.keyword)this.unexpected();let name=this.type===tt.name?this.value:this.type.keyword;return this.next(),name}$23(){let type=this.$24();while(!this.hasPrecedingLineBreak()&&this.eat(tt.bracketL)){let node=this.startNodeAt(type.start,type.loc?.start);if(this.eat(tt.bracketR))node.elementType=type,type=this.finishNode(node,"TSArrayType");else node.objectType=type,node.indexType=this.$0(),this.expect(tt.bracketR),type=this.finishNode(node,"TSIndexedAccessType")}return type}$24(){switch(this.type){case tt.name:case tt._void:case tt._null:{let keyword=KEYWORD_TYPES.get(this.value);if(keyword&&(this.type!==tt.name||!this.containsEsc&&this.$2()!==CHAR_DOT)){let node=this.startNode();return this.next(),this.finishNode(node,keyword)}return this.$1c()}case tt.string:case tt.num:case tt._true:case tt._false:{let node=this.startNode();return node.literal=this.parseExprAtom(),this.finishNode(node,"TSLiteralType")}case tt.plusMin:{if(this.value!=="-")break;let node=this.startNode(),unary=this.startNode();if(this.next(),this.type!==tt.num)this.unexpected();return unary.operator="-",unary.prefix=!0,unary.argument=this.parseExprAtom(),node.literal=this.finishNode(unary,"UnaryExpression"),this.finishNode(node,"TSLiteralType")}case tt.backQuote:return this.$25();case tt._this:{let thisType=this.$w();if(this.isContextual("is")&&!this.hasPrecedingLineBreak()){let node=this.startNodeAt(thisType.start,thisType.loc?.start);return node.parameterName=thisType,this.$x(node,!1)}return thisType}case tt._typeof:return this.$26();case tt._import:return this.$1d();case tt.braceL:return this.$27()?this.$28():this.$29();case tt.bracketL:return this.$2a();case tt.parenL:{let node=this.startNode();return this.next(),node.typeAnnotation=this.$0(),this.expect(tt.parenR),this.finishNode(node,"TSParenthesizedType")}default:if(this.type.keyword)return this.$1c()}return this.unexpected()}$1c(){let node=this.startNode();if(node.typeName=this.$j(),!this.hasPrecedingLineBreak()&&this.$1())node.typeArguments=this.$e();return this.finishNode(node,"TSTypeReference")}$j(){let entity=this.parseIdent(!0);while(this.eat(tt.dot)){let node=this.startNodeAt(entity.start,entity.loc?.start);node.left=entity,node.right=this.parseIdent(!0),entity=this.finishNode(node,"TSQualifiedName")}return entity}$26(){let node=this.startNode();if(this.next(),node.exprName=this.type===tt._import?this.$1d():this.$j(),!this.hasPrecedingLineBreak()&&this.$1())node.typeArguments=this.$e();return this.finishNode(node,"TSTypeQuery")}$1d(){let node=this.startNode();if(this.next(),node.argument=this.$1e(),this.eat(tt.dot))node.qualifier=this.$j();if(this.$1())node.typeArguments=this.$e();return this.finishNode(node,"TSImportType")}$z(){if(this.type!==tt.string)this.unexpected();return this.parseExprAtom()}$1e(){this.expect(tt.parenL);let string=this.$z();return this.expect(tt.parenR),string}$25(){let node=this.startNode(),literal=this.startNode();this.next(),literal.expressions=[];let element=this.parseTemplateElement({isTagged:!1});literal.quasis=[element];while(!element.tail){if(this.type===tt.eof)this.raise(this.pos,"Unterminated template literal");this.expect(tt.dollarBraceL),literal.expressions.push(this.$0()),this.expect(tt.braceR),element=this.parseTemplateElement({isTagged:!1}),literal.quasis.push(element)}return this.next(),node.literal=this.finishNode(literal,"TemplateLiteral"),this.finishNode(node,"TSLiteralType")}$27(){return this.$v(()=>{if(this.next(),this.type===tt.plusMin)return this.next(),this.isContextual("readonly");if(this.isContextual("readonly"))this.next();if(this.type!==tt.bracketL)return!1;if(this.next(),this.type!==tt.name)return!1;return this.next(),this.type===tt._in})}$28(){let node=this.startNode();if(this.expect(tt.braceL),this.type===tt.plusMin)node.readonly=this.value,this.next(),this.expectContextual("readonly");else if(this.eatContextual("readonly"))node.readonly=!0;this.expect(tt.bracketL);let parameter=this.startNode();if(parameter.name=this.$y(),this.expect(tt._in),parameter.constraint=this.$0(),node.typeParameter=this.finishNode(parameter,"TSTypeParameter"),node.nameType=this.eatContextual("as")?this.$0():null,this.expect(tt.bracketR),this.type===tt.plusMin)node.optional=this.value,this.next(),this.expect(tt.question);else if(this.eat(tt.question))node.optional=!0;if(this.eat(tt.colon))node.typeAnnotation=this.$0();return this.semicolon(),this.expect(tt.braceR),this.finishNode(node,"TSMappedType")}$29(){let node=this.startNode();return node.members=this.$1f(),this.finishNode(node,"TSTypeLiteral")}$1f(){this.expect(tt.braceL);let members=[];while(!this.eat(tt.braceR))members.push(this.$2b());return members}$2b(){let node=this.startNode(),type="TSPropertySignature",next=this.type===tt._new?this.$2():-1;if(this.type===tt.parenL||this.$1())type="TSCallSignatureDeclaration",this.$r(node,tt.colon);else if(next===CHAR_PAREN_L||next===CHAR_LT)type="TSConstructSignatureDeclaration",this.next(),this.$r(node,tt.colon);else{let newKey=this.type===tt._new?this.parseIdent(!0):null;if(this.isContextual("readonly")&&this.$s(!0))this.next(),node.readonly=!0;if(this.type===tt.bracketL&&this.$1g())return this.$1h(node);let kind="method";if(newKey)node.key=newKey;else{if((this.isContextual("get")||this.isContextual("set"))&&this.$s(!1))kind=this.value,this.next();this.parsePropertyName(node)}if(this.eat(tt.question))node.optional=!0;if(this.type===tt.parenL||this.$1()){if(type="TSMethodSignature",kind!=="method")node.kind=kind;this.$r(node,tt.colon),node.kind=kind}else if(this.type===tt.colon)node.typeAnnotation=this.$6()}return this.$1i(),this.finishNode(node,type)}$1i(){if(!this.eat(tt.comma))this.semicolon()}$1g(){return this.$v(()=>{if(this.next(),this.type!==tt.name)return!1;return this.next(),this.type===tt.colon})}$1h(node){if(this.expect(tt.bracketL),node.parameters=[this.$h(this.parseIdent(),!1)],this.expect(tt.bracketR),this.type===tt.colon)node.typeAnnotation=this.$6();return this.$1i(),this.finishNode(node,"TSIndexSignature")}$2a(){let node=this.startNode();this.expect(tt.bracketL),node.elementTypes=[];while(!this.eat(tt.bracketR))if(node.elementTypes.push(this.$2c()),this.type!==tt.bracketR)this.expect(tt.comma);return this.finishNode(node,"TSTupleType")}$2c(){let start=this.start,startLoc=this.startLoc,rest=this.eat(tt.ellipsis),element;if((this.type===tt.name||this.type.keyword)&&this.$2d()){let node=this.startNode();node.label=this.parseIdent(!0),node.optional=this.eat(tt.question),this.expect(tt.colon),node.elementType=this.$0(),element=this.finishNode(node,"TSNamedTupleMember")}else if(element=this.$0(),this.eat(tt.question)){let node=this.startNodeAt(element.start,element.loc?.start);node.typeAnnotation=element,element=this.finishNode(node,"TSOptionalType")}if(rest){let node=this.startNodeAt(start,startLoc);node.typeAnnotation=element,element=this.finishNode(node,"TSRestType")}return element}$2d(){let at=this.$d();if(this.input.charCodeAt(at)===63)at=this.$d(at+1);return this.input.charCodeAt(at)===CHAR_COLON}$8(){return this.$a(()=>{let node=this.startNode();this.next(),node.params=[];while(!this.$c()){let parameter=this.startNode();while((this.type===tt._const||this.type===tt._in||this.isContextual("out"))&&isIdentifierStart(this.$2()))parameter[this.value]=!0,this.next();if(parameter.name=this.$y(),this.eat(tt._extends))parameter.constraint=this.$0();if(this.eat(tt.eq))parameter.default=this.$0();if(node.params.push(this.finishNode(parameter,"TSTypeParameter")),!this.$c()){if(this.expect(tt.comma),this.$c())node.extra={trailingComma:this.lastTokStart}}}if(this.next(),node.params.length===0)this.$1y(this.start,"Type parameter list cannot be empty.");return this.finishNode(node,"TSTypeParameterDeclaration")})}$e(){return this.$a(()=>{let node=this.startNode();this.next(),node.params=[];while(!this.$c())if(node.params.push(this.$0()),!this.$c())this.expect(tt.comma);if(node.params.length===0)this.unexpected();return this.next(),this.finishNode(node,"TSTypeParameterInstantiation")})}$1j(){let list=[];do{let node=this.startNode();if(node.expression=this.$j(),this.$1())node.typeParameters=this.$e();list.push(this.finishNode(node,"TSExpressionWithTypeArguments"))}while(this.eat(tt.comma));return list}$1k(exported=!1){if(this.type!==tt.name||this.containsEsc){if(this.type===tt._const&&this.$3()==="enum")return this.$10(this.startNode());return}if(!this.$2e(this.value))return;if(this.value==="declare")return this.$2f(exported);return this.$1l(this.startNode(),this.value)}$2e(word){switch(word){case"interface":case"type":case"namespace":return this.$14();case"enum":return isIdentifierStart(this.$2());case"abstract":return this.$b()&&this.$3()==="class";case"module":{let next=this.$2();return this.$b()&&(next===CHAR_DQUOTE||next===CHAR_SQUOTE||isIdentifierStart(next))}case"declare":return this.$b()&&DECLARE_TARGETS.has(this.$3());case"global":return this.$b()&&this.$2()===CHAR_BRACE_L}return!1}$1l(node,word){switch(word){case"interface":return this.$1m(node);case"type":return this.$2g(node);case"enum":return this.$10(node);case"abstract":return this.$1n(node,!0);case"global":return node.global=!0,node.id=this.parseIdent(),node.body=this.$11(),this.finishNode(node,"TSModuleDeclaration")}return this.$2h(node)}$2f(exported){let old=this.$5;this.$5=!0;let node=this.startNode();this.next();let word=this.value;if(word==="const"&&this.$3()==="enum")node.const=!0;if(!exported&&DECLARE_FIRST.has(word))node.declare=!0;let declaration;if(node.const)declaration=this.$10(node);else if(word==="var"||word==="let"||word==="const")declaration=this.parseVarStatement(node,word,!0);else if(word==="function")this.next(),declaration=this.parseFunction(node,FUNC_STATEMENT,!1,!1);else if(word==="class")declaration=this.parseClass(node,!0);else declaration=this.$1l(node,word);return declaration.declare=!0,this.$5=old,declaration}$1n(node,isStatement){return this.next(),node.abstract=!0,this.parseClass(node,isStatement)}$1m(node){if(this.next(),node.id=this.parseIdent(),this.checkLValSimple(node.id,BIND_TS_INTERFACE),this.$1())node.typeParameters=this.$8();return this.$a(()=>{if(this.eat(tt._extends))node.extends=this.$1j();let body=this.startNode();body.body=this.$1f(),node.body=this.finishNode(body,"TSInterfaceBody")}),this.finishNode(node,"TSInterfaceDeclaration")}$2g(node){if(this.next(),node.id=this.parseIdent(),this.checkLValSimple(node.id,BIND_TS_TYPE),this.$1())node.typeParameters=this.$8();return node.typeAnnotation=this.$a(()=>(this.expect(tt.eq),this.$0())),this.semicolon(),this.finishNode(node,"TSTypeAliasDeclaration")}$10(node){if(this.type===tt._const)node.const=!0,this.next();this.next(),node.id=this.parseIdent(),this.checkLValSimple(node.id,BIND_TS_ENUM),this.expect(tt.braceL),node.members=[];while(!this.eat(tt.braceR)){let member=this.startNode();if(member.id=this.type===tt.string?this.parseExprAtom():this.parseIdent(!0),this.eat(tt.eq))member.initializer=this.parseMaybeAssign();if(node.members.push(this.finishNode(member,"TSEnumMember")),this.type!==tt.braceR)this.expect(tt.comma)}return this.finishNode(node,"TSEnumDeclaration")}$2h(node){if(this.next(),this.type===tt.string){if(node.id=this.parseExprAtom(),this.type===tt.braceL)node.body=this.$11();else this.semicolon();return this.finishNode(node,"TSModuleDeclaration")}return node.id=this.parseIdent(),this.checkLValSimple(node.id,BIND_TS_NAMESPACE),this.$1o(node)}$1o(node){if(this.eat(tt.dot)){let inner=this.startNode();inner.id=this.parseIdent(),node.body=this.$1o(inner)}else node.body=this.$11();return this.finishNode(node,"TSModuleDeclaration")}$11(){this.enterScope(SCOPE_CLASS_STATIC_BLOCK);let node=this.startNode();this.enterScope(0),this.expect(tt.braceL),node.body=[];while(!this.eat(tt.braceR))node.body.push(this.parseStatement(null,!0));return this.exitScope(),this.exitScope(),this.finishNode(node,"TSModuleBlock")}$1p(node,isExport){if(node.isExport=isExport,node.id=this.parseIdent(),this.checkLValSimple(node.id,BIND_LEXICAL),this.expect(tt.eq),this.isContextual("require")&&this.$2()===CHAR_PAREN_L){let reference=this.startNode();this.next(),reference.expression=this.$1e(),node.moduleReference=this.finishNode(reference,"TSExternalModuleReference")}else node.moduleReference=this.$j();return this.semicolon(),this.finishNode(node,"TSImportEqualsDeclaration")}$2i(){let at=this.$d();if(this.input.charCodeAt(at)!==CHAR_EQ)return!1;let after=this.input.charCodeAt(at+1);return after!==CHAR_EQ&&after!==62}parseStatement(context,topLevel,exports){if(this.type===atType)this.$1q(!0);let declaration=this.$1k();if(declaration)return declaration;return super.parseStatement(context,topLevel,exports)}parseVarStatement(node,kind,allowMissingInitializer){return super.parseVarStatement(node,kind,allowMissingInitializer||this.$5)}parseVarId(decl,kind){if(super.parseVarId(decl,kind),decl.id.type==="Identifier"&&this.$u()&&!this.hasPrecedingLineBreak())this.next(),decl.definite=!0;this.$h(decl.id,!1)}parseCatchClauseParam(){let param=this.$h(this.parseBindingAtom(),!1),simple=param.type==="Identifier";return this.enterScope(simple?SCOPE_SIMPLE_CATCH:0),this.checkLValPattern(param,simple?BIND_SIMPLE_CATCH:BIND_LEXICAL),this.expect(tt.parenR),param}parseImport(node){if(this.next(),node.importKind="value",this.type===tt.string)node.specifiers=[],node.source=this.parseExprAtom();else{if(this.isContextual("type")){let next=this.$2();if(next===CHAR_BRACE_L||next===CHAR_STAR||isIdentifierStart(next)&&this.$3()!=="from")node.importKind="type",this.next()}if(this.type===tt.name&&this.$2i())return this.$1p(node,!1);node.specifiers=this.parseImportSpecifiers(),this.expectContextual("from"),node.source=this.$z()}return this.$1r(node),this.semicolon(),this.finishNode(node,"ImportDeclaration")}parseWithClause(){if(this.isContextual("assert")&&!this.hasPrecedingLineBreak())this.type=tt._with;return this.type===tt._with?super.parseWithClause():void 0}$1r(node){let attributes=this.parseWithClause();if(attributes)node.attributes=attributes}parseImportSpecifier(){return this.$1s("importKind",()=>super.parseImportSpecifier())}parseExportSpecifier(exports){return this.$1s("exportKind",()=>super.parseExportSpecifier(exports))}$1s(kindKey,parse){let next=this.isContextual("type")?this.$2():-1;if(next===CHAR_DQUOTE||next===CHAR_SQUOTE||isIdentifierStart(next)&&this.$3()!=="as"){let modifier=this.startNode();this.next();let node=parse();return this.$q(node,modifier),node[kindKey]="type",node}let node=parse();return node[kindKey]="value",node}parseExport(node,exports){if(this.next(),this.eat(tt._import)){if(node.importKind="value",this.isContextual("type")&&isIdentifierStart(this.$2())&&this.$3()!=="from")node.importKind="type",this.next();return this.$1p(node,!0)}if(this.eat(tt.eq))return node.expression=this.parseExpression(),this.semicolon(),this.finishNode(node,"TSExportAssignment");if(this.eatContextual("as"))return this.expectContextual("namespace"),node.id=this.parseIdent(),this.semicolon(),this.finishNode(node,"TSNamespaceExportDeclaration");if(node.exportKind="value",this.isContextual("type")){let next=this.$2();if(next===CHAR_BRACE_L||next===CHAR_STAR)node.exportKind="type",this.next()}if(this.eat(tt.star))return this.parseExportAllDeclaration(node,exports);if(this.eat(tt._default)){if(this.isContextual("interface")&&this.$14())node.declaration=this.$1m(this.startNode());else if(this.isContextual("abstract")&&this.$3()==="class")node.declaration=this.$1n(this.startNode(),"nullableID");else node.declaration=this.parseExportDefaultDeclaration();return this.finishNode(node,"ExportDefaultDeclaration")}let isDeclare=this.isContextual("declare"),declaration=this.$1k(!0);if(declaration||this.shouldParseExportStatement()){if(node.declaration=declaration??this.parseStatement(null),isDeclare||node.declaration.type==="TSInterfaceDeclaration"||node.declaration.type==="TSTypeAliasDeclaration")node.exportKind="type";return node.specifiers=[],node.source=null,this.finishNode(node,"ExportNamedDeclaration")}if(node.declaration=null,node.specifiers=this.parseExportSpecifiers(exports),this.eatContextual("from"))node.source=this.$z(),this.$1r(node);else{for(let spec of node.specifiers)if(this.checkUnreserved(spec.local),this.checkLocalExport(spec.local),spec.local.type==="Literal")this.raise(spec.local.start,"A string literal cannot be used as an exported binding without `from`.");node.source=null}return this.semicolon(),this.finishNode(node,"ExportNamedDeclaration")}parseFunction(node,statement,allowExpressionBody,isAsync,forInit){let isDeclaration=statement&FUNC_STATEMENT;if(isDeclaration)this.$f=node,this.$o=node.start;super.parseFunction(node,statement,allowExpressionBody,isAsync,forInit),this.$f=null;let bodiless=!node.body;if(bodiless)node.type="TSDeclareFunction";if(isDeclaration&&node.id){if(bodiless){if(this.$5&&this.currentScope().flags&SCOPE_TOP)this.declareName(node.id.name,BIND_FLAGS_TS_EXPORT_ONLY,node.id.start);this.checkLValSimple(node.id,BIND_NONE)}else if(!(statement&FUNC_HANGING_STATEMENT)){let bindingType=BIND_FUNCTION;if(this.strict||node.generator||node.async)bindingType=this.treatFunctionsAsVar?BIND_VAR:BIND_LEXICAL;this.checkLValSimple(node.id,bindingType)}}return node}parseFunctionParams(node){if(this.$1())node.typeParameters=this.$8();if(super.parseFunctionParams(node),this.type===tt.colon)node.returnType=this.$6(!0)}parseFunctionBody(node,isArrowFunction,isMethod,forInit){if(isMethod&&this.type===tt.colon)node.returnType=this.$6(!0);if(isArrowFunction||this.type===tt.braceL||node.start!==this.$o){super.parseFunctionBody(node,isArrowFunction,isMethod,forInit);return}this.semicolon(),this.exitScope()}parseMethod(isGenerator,isAsync,allowDirectSuper){let typeParameters=this.$k;this.$k=null;let node=super.parseMethod(isGenerator,isAsync,allowDirectSuper);if(!node.body)node.type="TSDeclareMethod";if(typeParameters)node.typeParameters=typeParameters;return node}parseBindingList(close,allowEmpty,allowTrailingComma,allowModifiers){let modifiers=allowModifiers===!0||this.$l;return this.$l=!1,super.parseBindingList(close,allowEmpty,allowTrailingComma,modifiers)}$s(allowLineBreak){if(!allowLineBreak&&!this.$b())return!1;let next=this.$2();return next===CHAR_BRACKET_L||next===CHAR_BRACE_L||next===CHAR_STAR||next===CHAR_DOT||next===CHAR_HASH||next===CHAR_DQUOTE||next===CHAR_SQUOTE||next>=48&&next<=57||isIdentifierStart(next)}parseAssignableListItem(allowModifiers){let decorators=this.$12(),start=this.start,startLoc=this.startLoc,accessibility,readonly=!1,override=!1;if(allowModifiers)while(this.type===tt.name&&PARAMETER_MODIFIERS.has(this.value)&&!this.containsEsc&&this.$s(!1)){if(this.value==="readonly")readonly=!0;else if(this.value==="override")override=!0;else accessibility=this.value;this.next()}let left;if(this.type===tt._this)left=this.startNode(),left.name="this",this.next(),this.finishNode(left,"Identifier");else left=this.parseBindingAtom();let element=this.type===tt.eq?this.parseMaybeDefault(start,startLoc,left):this.parseMaybeDefault(left.start,left.loc?.start,this.$h(left,!0));if(decorators.length>0)element.decorators=decorators;if(!accessibility&&!readonly&&!override)return element;let node=this.startNodeAt(start,startLoc);if(accessibility)node.accessibility=accessibility;if(readonly)node.readonly=!0;if(override)node.override=!0;return node.parameter=element,this.finishNode(node,"TSParameterProperty")}parseBindingListItem(param){if(param.type==="RestElement")this.$h(param,!0);return param}checkLValSimple(expr,bindingType,checkClashes){if(this.$f&&expr===this.$f.id){this.$f=null;return}if(!bindingType&&TS_EXPRESSION_WRAPPERS.has(expr.type)){this.checkLValSimple(expr.expression,bindingType,checkClashes);return}switch(expr.type){case"TSParameterProperty":this.checkLValInnerPattern(expr.parameter,bindingType,checkClashes);return;case"Identifier":if(expr.name==="this")return}super.checkLValSimple(expr,bindingType,checkClashes)}toAssignable(node,isBinding,refDestructuringErrors){if(node&&!isBinding&&TS_EXPRESSION_WRAPPERS.has(node.type))return node;return super.toAssignable(node,isBinding,refDestructuringErrors)}declareName(name,bindingType,pos){let scope=this.currentScope();if(bindingType&BIND_FLAGS_TS_EXPORT_ONLY){this.$1t(scope,name),scope.$1u??=[],scope.$1u.push(name);return}if(bindingType===BIND_TS_TYPE||bindingType===BIND_TS_INTERFACE){if(scope.$13??=[],bindingType===BIND_TS_TYPE&&hasName(scope.$13,name))this.raise(pos,`type '${name}' has already been declared.`);scope.$13.push(name),this.$1t(scope,name);return}if(bindingType&BIND_FLAGS_TS_ENUM){if(scope.$1v??=[],hasName(scope.$1v,name))return;super.declareName(name,BIND_LEXICAL,pos),scope.$1v.push(name);return}super.declareName(name,bindingType,pos)}$1t(scope,name){if(this.inModule&&scope.flags&SCOPE_TOP)delete this.undefinedExports[name]}checkLocalExport(id){for(let i=this.scopeStack.length-1;i>=0;i--){let scope=this.scopeStack[i];if(hasName(scope.$13,id.name)||hasName(scope.$1u,id.name))return}super.checkLocalExport(id)}checkExport(){}raiseRecoverable(pos,message){if(message==="Duplicate constructor in the same class")return;super.raiseRecoverable(pos,message)}$12(){let decorators=[];while(this.type===atType)decorators.push(this.$1w());return decorators}$1q(allowExport){let pending=this.$9[this.$9.length-1];while(this.type===atType)pending.push(this.$1w());if(this.type===tt._export){if(!allowExport)this.unexpected()}else if(this.type!==tt._class&&!((this.isContextual("abstract")||this.isContextual("declare"))&&this.$3()==="class"))this.raise(this.start,"Leading decorators must be attached to a class declaration.")}$1w(){let node=this.startNode();this.next(),this.$9.push([]);let startPos=this.start,startLoc=this.startLoc,expression;if(this.type===tt.parenL){if(this.next(),expression=this.parseExpression(),this.expect(tt.parenR),this.options.preserveParens){let paren=this.startNodeAt(startPos,startLoc);paren.expression=expression,expression=this.finishNode(paren,"ParenthesizedExpression")}}else{expression=this.parseIdent(!1);while(this.eat(tt.dot)){let member=this.startNodeAt(startPos,startLoc);member.object=expression,member.property=this.parseIdent(!0),member.computed=!1,expression=this.finishNode(member,"MemberExpression")}}let typeArguments=this.$p()?this.$e():void 0;if(this.eat(tt.parenL)){let call=this.startNodeAt(expression.start,expression.loc?.start);if(call.callee=expression,call.arguments=this.parseExprList(tt.parenR,!1,!1),typeArguments)call.typeArguments=typeArguments;expression=this.finishNode(call,"CallExpression")}else if(typeArguments){let instantiation=this.startNodeAt(expression.start,expression.loc?.start);instantiation.expression=expression,instantiation.typeArguments=typeArguments,expression=this.finishNode(instantiation,"TSInstantiationExpression")}return node.expression=expression,this.$9.pop(),this.finishNode(node,"Decorator")}shouldParseExportStatement(){return this.type===atType||super.shouldParseExportStatement()}parseExprAtom(refDestructuringErrors,forInit,forNew){if(this.type===atType)this.$1q(!1);return super.parseExprAtom(refDestructuringErrors,forInit,forNew)}parseProperty(isPattern,refDestructuringErrors){if(isPattern||this.type!==atType)return super.parseProperty(isPattern,refDestructuringErrors);let decorators=this.$12(),property=super.parseProperty(isPattern,refDestructuringErrors);if(property.type==="SpreadElement")this.raise(property.start,"Decorators can't be used with SpreadElement");return property.decorators=decorators,property}parseClassId(node,isStatement){let index=this.$9.length-1,decorators=this.$9[index];if(decorators.length>0)node.decorators=decorators,this.$q(node,decorators[0]),this.$9[index]=[];if(!this.isContextual("implements")||isStatement===!0)super.parseClassId(node,isStatement);if(this.$1())node.typeParameters=this.$8()}parseClassSuper(node){if(super.parseClassSuper(node),node.superClass&&this.$1())node.superTypeParameters=this.$e();if(this.eatContextual("implements"))node.implements=this.$a(()=>this.$1j())}parseClassElement(constructorAllowsSuper){if(this.type===atType){let decorators=this.$12();if(this.type===tt.braceR)this.raise(this.start,"Decorators must be attached to a class element.");let element=this.parseClassElement(constructorAllowsSuper);return element.decorators=decorators,this.$q(element,decorators[0]),element}if(this.eat(tt.semi))return null;let node=this.startNode();while(this.type===tt.name&&CLASS_MODIFIERS.has(this.value)&&!this.containsEsc&&this.$s(this.value==="static")){let modifier=this.value;if(this.next(),modifier==="static"&&this.type===tt.braceL)return this.next(),this.parseClassStaticBlock(node),node;if(modifier==="public"||modifier==="private"||modifier==="protected")node.accessibility=modifier;else node[modifier]=!0}if(this.type===tt.bracketL&&this.$1g())return this.$1h(node);node.static??=!1;let keyName="",isGenerator=!1,isAsync=!1,kind="method";if(this.eatContextual("async"))if((this.isClassElementNameStart()||this.type===tt.star)&&!this.canInsertSemicolon())isAsync=!0;else keyName="async";if(!keyName&&this.eat(tt.star))isGenerator=!0;if(!keyName&&!isAsync&&!isGenerator){let lastValue=this.value;if(this.eatContextual("get")||this.eatContextual("set"))if(this.isClassElementNameStart())kind=lastValue;else keyName=lastValue}if(keyName)node.computed=!1,node.key=this.startNodeAt(this.lastTokStart,this.lastTokStartLoc),node.key.name=keyName,this.finishNode(node.key,"Identifier");else this.parseClassElementName(node);if(this.eat(tt.question))node.optional=!0;if(this.type===tt.parenL||this.$1()||kind!=="method"||isGenerator||isAsync){let key=node.key,isConstructor=!node.static&&!node.computed&&(key.type==="Identifier"&&key.name==="constructor"||key.type==="Literal"&&key.value==="constructor");if(node.kind=isConstructor?"constructor":kind,this.$1())node.typeParameters=this.$8();this.$l=isConstructor,this.$o=this.start,this.parseClassMethod(node,isGenerator,isAsync,isConstructor&&constructorAllowsSuper)}else{if(!node.optional&&this.$u())this.next(),node.definite=!0;if(this.type===tt.colon)node.typeAnnotation=this.$6();this.parseClassField(node)}return node}parseMaybeAssign(forInit,refDestructuringErrors,afterLeftParse){if(this.$p()){let arrow=this.$g(()=>{let typeParameters=this.$8(),expr=super.parseMaybeAssign(forInit,refDestructuringErrors,afterLeftParse);if(expr.type!=="ArrowFunctionExpression")return;return expr.typeParameters=typeParameters,this.$q(expr,typeParameters),expr});if(arrow)return arrow}return super.parseMaybeAssign(forInit,refDestructuringErrors,afterLeftParse)}parseMaybeUnary(refDestructuringErrors,sawUnary,incDec,forInit){if(this.$p()){let node=this.startNode();return node.typeAnnotation=this.$a(()=>{this.next();let type=this.$0();if(!this.$c())this.unexpected();return this.next(),type}),node.expression=this.parseMaybeUnary(null,!1,!1,forInit),this.finishNode(node,"TSTypeAssertion")}return super.parseMaybeUnary(refDestructuringErrors,sawUnary,incDec,forInit)}parseMaybeConditional(forInit,refDestructuringErrors){let startPos=this.start,startLoc=this.startLoc,expr=this.parseExprOps(forInit,refDestructuringErrors);if(this.checkExpressionErrors(refDestructuringErrors))return expr;if(this.type===tt.question&&!(expr.type==="ArrowFunctionExpression"&&expr.start===startPos)&&!this.$2j()){this.next();let node=this.startNodeAt(startPos,startLoc);return node.test=expr,node.consequent=this.parseMaybeAssign(),this.expect(tt.colon),node.alternate=this.parseMaybeAssign(forInit),this.finishNode(node,"ConditionalExpression")}return expr}$2j(){let at=this.$d(),next=this.input.charCodeAt(at);if(next===CHAR_COLON||next===CHAR_COMMA||next===CHAR_PAREN_R)return!0;return next===CHAR_EQ&&this.input.charCodeAt(at+1)!==CHAR_EQ}parseParenItem(item){return this.$h(item,!0)}$1x(){if(this.type!==tt.colon)return!0;let returnType=this.$g(()=>{let type=this.$6(!0);return this.type===tt.arrow&&!this.canInsertSemicolon()?type:void 0});if(!returnType)return!1;return this.$7=returnType,!0}shouldParseArrow(exprList){return this.$1x()&&super.shouldParseArrow(exprList)}shouldParseAsyncArrow(){return this.$1x()&&super.shouldParseAsyncArrow()}parseArrowExpression(node,params,isAsync,forInit){if(this.$7)node.returnType=this.$7,this.$7=null;return super.parseArrowExpression(node,params,isAsync,forInit)}parseExprList(close,allowTrailingComma,allowEmpty,refDestructuringErrors){if(!this.$m)return super.parseExprList(close,allowTrailingComma,allowEmpty,refDestructuringErrors);this.$m=!1;let elements=[],first=!0;while(!this.eat(close)){if(first)first=!1;else if(this.expect(tt.comma),allowTrailingComma&&this.afterTrailingComma(close))break;if(this.type===tt.ellipsis){let spread=this.parseSpread(refDestructuringErrors);if(this.eat(tt.question))spread.optional=!0;if(this.type===tt.colon)spread.typeAnnotation=this.$6();elements.push(spread)}else elements.push(this.parseMaybeAssign(!1,refDestructuringErrors,this.parseParenItem))}return elements}parseSubscript(base,startPos,startLoc,noCalls,maybeAsyncArrow,optionalChained,forInit){if(this.$u()&&!this.hasPrecedingLineBreak()){let node=this.startNodeAt(startPos,startLoc);return this.exprAllowed=!1,this.next(),node.expression=base,this.finishNode(node,"TSNonNullExpression")}if(maybeAsyncArrow&&this.$1()){let arrow=this.$g(()=>this.$2k(startPos,startLoc,forInit));if(arrow)return arrow}let optional=this.type===tt.questionDot&&this.$2()===CHAR_LT;if(this.$1()||optional||this.type===tt.bitShift&&this.value==="<<"){let typeArguments=this.$g(()=>{if(optional)this.next();this.$p();let args=this.$e();if(this.type===tt.parenL&&!noCalls)return args;if(this.type===tt.backQuote)return optional?void 0:args;if(optional)return;if(this.$c()||this.type===tt.bitShift||this.type.startsExpr&&this.type!==tt.parenL&&!this.hasPrecedingLineBreak())return;return args});if(typeArguments){let node=this.startNodeAt(startPos,startLoc);if(this.type===tt.parenL&&!noCalls){if(this.next(),node.callee=base,node.arguments=this.parseExprList(tt.parenR,!0,!1),node.typeArguments=typeArguments,optional)base.optional=!0;if(optional||optionalChained)node.optional=optional;return this.finishNode(node,"CallExpression")}if(this.type===tt.backQuote)return node.tag=base,node.quasi=this.parseTemplate({isTagged:!0}),node.typeArguments=typeArguments,this.finishNode(node,"TaggedTemplateExpression");return node.expression=base,node.typeArguments=typeArguments,this.finishNode(node,"TSInstantiationExpression")}}if(maybeAsyncArrow&&this.type===tt.parenL)this.$m=!0;return super.parseSubscript(base,startPos,startLoc,noCalls,maybeAsyncArrow,optionalChained,forInit)}$2k(startPos,startLoc,forInit){let node=this.startNodeAt(startPos,startLoc);if(node.typeParameters=this.$8(),this.expect(tt.parenL),node.params=this.parseBindingList(tt.parenR,!1,!0),this.type===tt.colon)node.returnType=this.$6(!0);if(this.type!==tt.arrow||this.canInsertSemicolon())return;return this.next(),this.parseArrowExpression(node,node.params,!0,forInit)}parseDynamicImport(node){if(this.next(),node.source=this.parseMaybeAssign(),this.eat(tt.comma)&&this.type!==tt.parenR)node.arguments=[this.parseExpression()];return this.expect(tt.parenR),this.finishNode(node,"ImportExpression")}parseNew(){let node=super.parseNew();if(node.callee?.type!=="TSInstantiationExpression")return node;let result=this.startNodeAt(node.start,node.loc?.start);return result.callee=node.callee.expression,result.typeArguments=node.callee.typeArguments,result.arguments=node.arguments,this.finishNodeAt(result,"NewExpression",node.end,node.loc?.end)}parseExprOp(left,leftStartPos,leftStartLoc,minPrec,forInit){if(tt._in.binop>minPrec&&this.type===tt.name&&(this.value==="as"||this.value==="satisfies")&&!this.containsEsc&&!this.hasPrecedingLineBreak()){let isSatisfies=this.value==="satisfies",node=this.startNodeAt(leftStartPos,leftStartLoc);return node.expression=left,node.typeAnnotation=this.$a(()=>{if(this.next(),!isSatisfies&&this.type===tt._const){let reference=this.startNode();return reference.typeName=this.parseIdent(!0),this.finishNode(reference,"TSTypeReference")}return this.$0()}),this.finishNode(node,isSatisfies?"TSSatisfiesExpression":"TSAsExpression"),this.parseExprOp(node,leftStartPos,leftStartLoc,minPrec,forInit)}return super.parseExprOp(left,leftStartPos,leftStartLoc,minPrec,forInit)}parseGetterSetter(prop){prop.kind=prop.key.name,super.parseGetterSetter(prop)}parsePropertyValue(prop,isPattern,isGenerator,isAsync,startPos,startLoc,refDestructuringErrors,containsEsc){if(!isPattern&&this.$1()){if(this.$k=this.$8(),this.type!==tt.parenL)this.unexpected();prop.kind="init"}return super.parsePropertyValue(prop,isPattern,isGenerator,isAsync,startPos,startLoc,refDestructuringErrors,containsEsc)}}return TSParser});
|
|
2
2
|
export{tsPlugin};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{setSource}from"./shared-m0dcdh24.js";import{parseStatementsAt}from"./shared-
|
|
1
|
+
import{setSource}from"./shared-m0dcdh24.js";import{parseStatementsAt}from"./shared-w3mxqtgj.js";import{scan}from"./shared-e4gbs4rb.js";function parseImportsExportsWith(source,options,typescript){setSource(source);let context={isTypeScript:options.typescript??!1,typescript,loc:!1,comments:!1,root:{comments:[]}};return parseStatementsAt(context,source,(parseAt)=>scan(source,options.localExports??!0,parseAt))}
|
|
2
2
|
export{parseImportsExportsWith};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{parseComponent}from"./shared-
|
|
1
|
+
import{parseComponent}from"./shared-qqrqzz29.js";import{htmlEntityNames}from"./shared-drb44hb9.js";import{TypeScriptParser}from"./shared-dscc5xg8.js";var support={typescript:TypeScriptParser,entityNames:htmlEntityNames};function parse2(source,options){return parseComponent(source,options,support)}
|
|
2
2
|
export{parse2};
|