sveast 0.9.5 → 0.9.6

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 CHANGED
@@ -25,7 +25,8 @@ ast.fragment.nodes; // [Text, RegularElement]
25
25
  | [`parseSections`](#parsesectionssource-options--astroot) | A component's AST without the markup: its `<script>`s, `<style>` and `<svelte:options>` | `sveast` |
26
26
  | [`parseModule`](#parsemodulesource-options--program) | A `.js` or `.ts` module's AST, the same as a component's `<script>` | `sveast` |
27
27
  | [`parseImportsExports`](#parseimportsexportssource-options--moduledeclaration) | A module's `import` and `export` statements, without parsing the rest | `sveast` |
28
- | [`lexImportsExports`](#leximportsexportssource--lexedstatement) | Their offsets, sources and names, without loading a parser | `sveast/lexer` |
28
+ | [`lexImportsExports`](#leximportsexportssource-options--lexedstatement) | Their offsets, sources and names, without loading a parser | `sveast/lexer` |
29
+ | [`lexDynamicImports`](#lexdynamicimportssource--lexeddynamicimport) | A module's `import(…)`, `require(…)` and `import.meta.glob(…)`, with their offsets and sources, without loading a parser | `sveast/lexer` |
29
30
  | [`lexComponent`](#lexcomponentsource--lexedcomponent) | A component's `<script>`s, `<style>` and `<svelte:options>`, with their attributes and offsets, without loading a parser | `sveast/lexer` |
30
31
  | [`lexStrings`](#lexstringssource--lexedstring) | A module's string and template literals, with their offsets and values, without loading a parser | `sveast/lexer` |
31
32
  | [`createParser`, `createModuleParser`](#smaller-bundles-sveastcore-and-sveastmodule) | The parsers without TypeScript, named HTML entities or the template parser, for a smaller bundle | `sveast/core`, `sveast/module` |
@@ -145,7 +146,7 @@ Parses a JavaScript or TypeScript module, such as a `.ts` file a component impor
145
146
 
146
147
  ### `parseImportsExports(source, options?) => ModuleDeclaration[]`
147
148
 
148
- A module's top-level `import` and `export` statements, without parsing the rest, e.g. to rewrite a component's imports or follow a module graph. Each node is the one `parseModule(source, { comments: false })` has for that statement: `ImportDeclaration`, `ExportNamedDeclaration`, `ExportDefaultDeclaration` and `ExportAllDeclaration`, and, in TypeScript, `TSImportEqualsDeclaration`, `TSExportAssignment` and `TSNamespaceExportDeclaration`. `import(...)` and `import.meta` are expressions, so they aren't returned. Unlike a regex, it never matches an `import` in a comment, a string, a template or a nested block such as `declare module "a" { ... }`.
149
+ A module's top-level `import` and `export` statements, without parsing the rest, e.g. to rewrite a component's imports or follow a module graph. Each node is the one `parseModule(source, { comments: false })` has for that statement: `ImportDeclaration`, `ExportNamedDeclaration`, `ExportDefaultDeclaration` and `ExportAllDeclaration`, and, in TypeScript, `TSImportEqualsDeclaration`, `TSExportAssignment` and `TSNamespaceExportDeclaration`. `import(...)` and `import.meta` are expressions, so they aren't returned; [`lexDynamicImports`](#lexdynamicimportssource--lexeddynamicimport) finds them. Unlike a regex, it never matches an `import` in a comment, a string, a template or a nested block such as `declare module "a" { ... }`.
149
150
 
150
151
  It stops after the last `import` or `export` that could start a statement, so the code after a component's imports is never read: on Carbon's component scripts, it takes a third of `parseModule`'s time, and about a seventh with `localExports: false`. A syntax error in a statement it returns throws a `ParseError`, including a name exported twice; errors elsewhere aren't reported.
151
152
 
@@ -164,12 +165,14 @@ function dependencies(source: string, typescript = false): string[] {
164
165
  }
165
166
  ```
166
167
 
167
- ### `lexImportsExports(source) => LexedStatement[]`
168
+ ### `lexImportsExports(source, options?) => LexedStatement[]`
168
169
 
169
170
  From `sveast/lexer`, and also `sveast`. A module's top-level `import` statements and `export … from` re-exports, read by hand instead of parsed, for a tool on a hot or eagerly loaded path, such as a preprocessor that rewrites a component's imports, that needs each statement's offsets, source and names, but not the AST. `sveast/lexer` loads no parser, so a fresh process imports it in 1.4 ms, and on Carbon's component scripts it takes 40% of the time `parseImportsExports` takes with `localExports: false`.
170
171
 
171
172
  It finds the statements `parseImportsExports` returns with `localExports: false`, with the same offsets, sources and names. It doesn't check syntax and never throws: a statement it can't read, such as `import { a from "a"` or `import a = require("a")`, has `source: null` and no specifiers, and ends where it stopped reading. `import type` and `type` before a name are always read.
172
173
 
174
+ With `exportLists: true`, it also returns each top-level `export { a, b as c }` without `from`, e.g. to follow a binding through an `index.js` that imports it and exports it again: `source` is `null`, and each specifier has kind `local`, with `local` the binding in this module. Those are the `ExportNamedDeclaration`s without a declaration that `parseImportsExports` returns with `localExports: true`; `export const a`, `export function b` and `export default` still aren't returned. A module that ends with an export list is read to its end.
175
+
173
176
  ```ts
174
177
  import { lexImportsExports } from "sveast/lexer";
175
178
 
@@ -181,7 +184,7 @@ for (const statement of lexImportsExports(source)) {
181
184
  statement.typeOnly; // `import type …` or `export type …`
182
185
  statement.specifiers;
183
186
  // import: { kind: "default" | "namespace" | "named", imported, local, typeOnly, start, end }
184
- // export: { kind: "all" | "namespace" | "named", local, exported, typeOnly, start, end }
187
+ // export: { kind: "all" | "namespace" | "named" | "local", local, exported, typeOnly, start, end }
185
188
  }
186
189
  ```
187
190
 
@@ -191,9 +194,29 @@ for (const statement of lexImportsExports(source)) {
191
194
  | `* as a` | `namespace`, `imported: "*"`, `local: "a"` | `namespace`, `local: "*"`, `exported: "a"` |
192
195
  | `*` | | `all`, `local: "*"`, `exported: null` |
193
196
  | `b as c`, `"b-c" as d` | `named`, `imported: "b"`, `local: "c"` | `named`, `local: "b"`, `exported: "c"` |
197
+ | `b as c` in `export { … }`, with `exportLists` | | `local`, `local: "b"`, `exported: "c"` |
194
198
 
195
199
  Names are as the module sees them: escapes decoded, and a string name without its quotes. A specifier's `typeOnly` is also `true` in an `import type` or `export type`. Its `start` is that of `type` before the name, if any, and `end` is after the last name; for `export *`, after the `*`.
196
200
 
201
+ ### `lexDynamicImports(source) => LexedDynamicImport[]`
202
+
203
+ From `sveast/lexer`, and also `sveast`. A module's `import(…)` and `require(…)` calls and Vite's `import.meta.glob(…)`, at any depth, in source order, read without parsing, e.g. to follow the lazily loaded part of a module graph. Unlike a regular expression, it never matches in a comment, a string, a template or a regular expression, and it tells a literal argument from a computed one. `lexImportsExports` finds the static imports; together they're a module's dependencies.
204
+
205
+ ```ts
206
+ import { lexDynamicImports } from "sveast/lexer";
207
+
208
+ for (const call of lexDynamicImports(source)) {
209
+ call.kind; // "import" | "require" | "glob"
210
+ call.start; // offset of `import` or `require`
211
+ call.end; // after the `)`
212
+ call.source; // { value: "./Chart.svelte", start, end } (quotes or backticks included), or null
213
+ }
214
+ ```
215
+
216
+ `source` is the first argument if it's a string or a template without `${…}` and it's followed by `)` or `,`, as in `import("a", { with: { type: "json" } })`; it's `null` for a computed argument such as `` import(`./${name}.js`) `` or `import.meta.glob(["a", "b"])`, and for a call without arguments. Type arguments are skipped, as in `import.meta.glob<Module>("./*.ts")`.
217
+
218
+ Where `parseModule` accepts the module, the calls are its `ImportExpression`s, its calls of an identifier `require`, `new require(…)` included, and of `import.meta.glob`, and in TypeScript also its `import("a")` types, as in `typeof import("a")`, and the `require("a")` of `import a = require("a")`. A method named `import` or `require`, such as `{ import() {} }`, isn't a call, and neither are `a.require(…)`, `require?.(…)` or `(require)(…)`. It doesn't check syntax and never throws. It matched `parseModule` on all 33,001 modules and component scripts it accepts from the projects under [Parity and performance](#parity-and-performance), svelte's tests and TypeScript's conformance tests.
219
+
197
220
  ### `lexComponent(source) => LexedComponent`
198
221
 
199
222
  From `sveast/lexer`, and also `sveast`. A component's top-level `<script>`, `<script module>`, `<style>` and `<svelte:options>`, with their attributes and the offsets of their tags and content, found without parsing: e.g. to read a component's scripts and their imports, its language or its options, or to rewrite a script, on a path that can't afford a parser. On the benchmark corpus it's about 50× faster than `parse`.
package/core.js CHANGED
@@ -1 +1 @@
1
- import"./shared-dgdrqgdn.js";import"./shared-m0dcdh24.js";import"./shared-2pngd0mg.js";import{ParseError2}from"./shared-nan648gn.js";import"./shared-5tpb3h6x.js";import{xmlEntityNames}from"./shared-bzqbnvee.js";import{parseComponent}from"./shared-xwzsb4m8.js";import"./shared-y3nf00py.js";import{parseModuleWith}from"./shared-z9y4mrek.js";import{parseImportsExportsWith}from"./shared-rvkvagj5.js";import{typeScriptParser,entityNamesOf}from"./shared-h6z1kjbb.js";function createParser(support={}){let typescript=typeScriptParser(support.typescript),internal={typescript,entityNames:entityNamesOf(support.entities)??xmlEntityNames};return{parse:(source,options)=>parseComponent(source,options,internal),parseModule:(source,options={})=>parseModuleWith(source,options,typescript),parseImportsExports:(source,options={})=>parseImportsExportsWith(source,options,typescript)}}export{ParseError2 as ParseError,createParser};
1
+ import"./shared-dgdrqgdn.js";import"./shared-m0dcdh24.js";import"./shared-2pngd0mg.js";import{ParseError2}from"./shared-nan648gn.js";import"./shared-5tpb3h6x.js";import{xmlEntityNames}from"./shared-bzqbnvee.js";import{parseComponent}from"./shared-xwzsb4m8.js";import"./shared-e4gbs4rb.js";import{parseModuleWith}from"./shared-z9y4mrek.js";import{parseImportsExportsWith}from"./shared-tapcgcpr.js";import{typeScriptParser,entityNamesOf}from"./shared-h6z1kjbb.js";function createParser(support={}){let typescript=typeScriptParser(support.typescript),internal={typescript,entityNames:entityNamesOf(support.entities)??xmlEntityNames};return{parse:(source,options)=>parseComponent(source,options,internal),parseModule:(source,options={})=>parseModuleWith(source,options,typescript),parseImportsExports:(source,options={})=>parseImportsExportsWith(source,options,typescript)}}export{ParseError2 as ParseError,createParser};
package/index.d.ts CHANGED
@@ -41,11 +41,11 @@ export interface LexedImportSpecifier {
41
41
  end: number;
42
42
  }
43
43
 
44
- /** A name an `export … from` re-exports. */
44
+ /** A name an `export … from` re-exports, or, with `exportLists`, one an `export { … }` without `from` exports. */
45
45
  export interface LexedExportSpecifier {
46
- /** `"all"` for `export *`, `"namespace"` for `export * as a`, `"named"` for a name in braces. */
47
- kind: "all" | "namespace" | "named";
48
- /** The name in the other module: `"*"` for `all` and `namespace`, or the name before `as`, with a string's value for `"a-b" as c`. */
46
+ /** `"all"` for `export *`, `"namespace"` for `export * as a`, `"named"` for a name in braces, `"local"` for a name in an `export { … }` without `from`. */
47
+ kind: "all" | "namespace" | "named" | "local";
48
+ /** The name in the other module: `"*"` for `all` and `namespace`, or the name before `as`, with a string's value for `"a-b" as c`; for `local`, the binding in this module. */
49
49
  local: string;
50
50
  /** The name it's exported as, or `null` for `export *`. */
51
51
  exported: string | null;
@@ -62,7 +62,7 @@ interface LexedStatementBase {
62
62
  start: number;
63
63
  /** The offset after the statement's `;`, or its last token without one. */
64
64
  end: number;
65
- /** The module it imports from, or `null` for a statement the lexer doesn't recognize. */
65
+ /** The module it imports from, or `null` for an `export { … }` without `from`, or a statement the lexer doesn't recognize. */
66
66
  source: LexedSource | null;
67
67
  /** Whether it's `import type` or `export type`. */
68
68
  typeOnly: boolean;
@@ -74,7 +74,7 @@ export interface LexedImport extends LexedStatementBase {
74
74
  specifiers: LexedImportSpecifier[];
75
75
  }
76
76
 
77
- /** An `export … from` statement. */
77
+ /** An `export … from` statement, or, with `exportLists`, an `export { … }` without `from`. */
78
78
  export interface LexedExport extends LexedStatementBase {
79
79
  kind: "export";
80
80
  specifiers: LexedExportSpecifier[];
@@ -82,6 +82,24 @@ export interface LexedExport extends LexedStatementBase {
82
82
 
83
83
  export type LexedStatement = LexedImport | LexedExport;
84
84
 
85
+ /** Options for {@link lexImportsExports}. */
86
+ export interface LexImportsExportsOptions {
87
+ /** Also return the module's `export { a, b as c }` statements without `from`, whose specifiers have kind `"local"`. Default `false`. */
88
+ exportLists?: boolean;
89
+ }
90
+
91
+ /** An `import(…)`, a `require(…)` or Vite's `import.meta.glob(…)`. */
92
+ export interface LexedDynamicImport {
93
+ /** `"import"` for `import(…)`, `"require"` for `require(…)`, `"glob"` for `import.meta.glob(…)`. */
94
+ kind: "import" | "require" | "glob";
95
+ /** The first argument, if it's a string or a template without `${…}` followed by `)` or `,`; `null` for a computed one. A template's `start` and `end` include its backticks. */
96
+ source: LexedSource | null;
97
+ /** The offset of `import` or `require`. */
98
+ start: number;
99
+ /** The offset after the closing `)`, or the end of the module without one. */
100
+ end: number;
101
+ }
102
+
85
103
  /** A string literal, or the text of a template literal between two of its delimiters. */
86
104
  export interface LexedString {
87
105
  /** `"string"` for a string literal, where `parseModule` has a `Literal`; `"template"` for a template's text, where it has a `TemplateElement`. */
@@ -105,7 +123,21 @@ export interface LexedString {
105
123
  * `source: null` and no specifiers, ending where it stopped reading.
106
124
  * TypeScript's `type` forms are always read.
107
125
  */
108
- export declare function lexImportsExports(source: string): LexedStatement[];
126
+ export declare function lexImportsExports(source: string, options?: LexImportsExportsOptions): LexedStatement[];
127
+
128
+ /**
129
+ * A module's `import(…)` and `require(…)` calls and Vite's
130
+ * `import.meta.glob(…)`, at any depth, in source order, read without a
131
+ * parser: each call's offsets and its first argument, if it's a string or
132
+ * a template without `${…}`. Comments, strings, templates and regular
133
+ * expressions are skipped, as {@link lexStrings} skips them, and it never
134
+ * throws. Where {@link parseModule} accepts the module, they are its
135
+ * `ImportExpression`s, its calls of an identifier `require` and of
136
+ * `import.meta.glob`, and, in TypeScript, its `import("a")` types and
137
+ * `import a = require("a")`. A method named `import` or `require` isn't a
138
+ * call.
139
+ */
140
+ export declare function lexDynamicImports(source: string): LexedDynamicImport[];
109
141
 
110
142
  /**
111
143
  * A module's string literals and the text of its template literals, in
package/index.js CHANGED
@@ -1 +1 @@
1
- import{isValidType}from"./is-valid-type.js";import{lexComponent,lexImportsExports,lexStrings}from"./lexer.js";import{parse}from"./parse.js";import{parseImportsExports}from"./parse-imports-exports.js";import{ParseError,parseModule}from"./parse-module.js";import{parseSections}from"./parse-sections.js";import{isRunesMode}from"./runes.js";import{analyzeScopes}from"./scope.js";import{children,createLocator,extractIdentifiers,forEachChild,isReference,locate,markupVisitorKeys,SKIP,STOP,skipTypeWrappers,valueVisitorKeys,visitorKeys,walk}from"./walk.js";export{ParseError,SKIP,STOP,analyzeScopes,children,createLocator,extractIdentifiers,forEachChild,isReference,isRunesMode,isValidType,lexComponent,lexImportsExports,lexStrings,locate,markupVisitorKeys,parse,parseImportsExports,parseModule,parseSections,skipTypeWrappers,valueVisitorKeys,visitorKeys,walk};
1
+ import{isValidType}from"./is-valid-type.js";import{lexComponent,lexDynamicImports,lexImportsExports,lexStrings}from"./lexer.js";import{parse}from"./parse.js";import{parseImportsExports}from"./parse-imports-exports.js";import{ParseError,parseModule}from"./parse-module.js";import{parseSections}from"./parse-sections.js";import{isRunesMode}from"./runes.js";import{analyzeScopes}from"./scope.js";import{children,createLocator,extractIdentifiers,forEachChild,isReference,locate,markupVisitorKeys,SKIP,STOP,skipTypeWrappers,valueVisitorKeys,visitorKeys,walk}from"./walk.js";export{ParseError,SKIP,STOP,analyzeScopes,children,createLocator,extractIdentifiers,forEachChild,isReference,isRunesMode,isValidType,lexComponent,lexDynamicImports,lexImportsExports,lexStrings,locate,markupVisitorKeys,parse,parseImportsExports,parseModule,parseSections,skipTypeWrappers,valueVisitorKeys,visitorKeys,walk};
package/lexer.d.ts CHANGED
@@ -24,11 +24,11 @@ export interface LexedImportSpecifier {
24
24
  end: number;
25
25
  }
26
26
 
27
- /** A name an `export … from` re-exports. */
27
+ /** A name an `export … from` re-exports, or, with `exportLists`, one an `export { … }` without `from` exports. */
28
28
  export interface LexedExportSpecifier {
29
- /** `"all"` for `export *`, `"namespace"` for `export * as a`, `"named"` for a name in braces. */
30
- kind: "all" | "namespace" | "named";
31
- /** The name in the other module: `"*"` for `all` and `namespace`, or the name before `as`, with a string's value for `"a-b" as c`. */
29
+ /** `"all"` for `export *`, `"namespace"` for `export * as a`, `"named"` for a name in braces, `"local"` for a name in an `export { … }` without `from`. */
30
+ kind: "all" | "namespace" | "named" | "local";
31
+ /** The name in the other module: `"*"` for `all` and `namespace`, or the name before `as`, with a string's value for `"a-b" as c`; for `local`, the binding in this module. */
32
32
  local: string;
33
33
  /** The name it's exported as, or `null` for `export *`. */
34
34
  exported: string | null;
@@ -45,7 +45,7 @@ interface LexedStatementBase {
45
45
  start: number;
46
46
  /** The offset after the statement's `;`, or its last token without one. */
47
47
  end: number;
48
- /** The module it imports from, or `null` for a statement the lexer doesn't recognize. */
48
+ /** The module it imports from, or `null` for an `export { … }` without `from`, or a statement the lexer doesn't recognize. */
49
49
  source: LexedSource | null;
50
50
  /** Whether it's `import type` or `export type`. */
51
51
  typeOnly: boolean;
@@ -57,7 +57,7 @@ export interface LexedImport extends LexedStatementBase {
57
57
  specifiers: LexedImportSpecifier[];
58
58
  }
59
59
 
60
- /** An `export … from` statement. */
60
+ /** An `export … from` statement, or, with `exportLists`, an `export { … }` without `from`. */
61
61
  export interface LexedExport extends LexedStatementBase {
62
62
  kind: "export";
63
63
  specifiers: LexedExportSpecifier[];
@@ -65,6 +65,24 @@ export interface LexedExport extends LexedStatementBase {
65
65
 
66
66
  export type LexedStatement = LexedImport | LexedExport;
67
67
 
68
+ /** Options for {@link lexImportsExports}. */
69
+ export interface LexImportsExportsOptions {
70
+ /** Also return the module's `export { a, b as c }` statements without `from`, whose specifiers have kind `"local"`. Default `false`. */
71
+ exportLists?: boolean;
72
+ }
73
+
74
+ /** An `import(…)`, a `require(…)` or Vite's `import.meta.glob(…)`. */
75
+ export interface LexedDynamicImport {
76
+ /** `"import"` for `import(…)`, `"require"` for `require(…)`, `"glob"` for `import.meta.glob(…)`. */
77
+ kind: "import" | "require" | "glob";
78
+ /** The first argument, if it's a string or a template without `${…}` followed by `)` or `,`; `null` for a computed one. A template's `start` and `end` include its backticks. */
79
+ source: LexedSource | null;
80
+ /** The offset of `import` or `require`. */
81
+ start: number;
82
+ /** The offset after the closing `)`, or the end of the module without one. */
83
+ end: number;
84
+ }
85
+
68
86
  /** A string literal, or the text of a template literal between two of its delimiters. */
69
87
  export interface LexedString {
70
88
  /** `"string"` for a string literal, where `parseModule` has a `Literal`; `"template"` for a template's text, where it has a `TemplateElement`. */
@@ -88,7 +106,21 @@ export interface LexedString {
88
106
  * `source: null` and no specifiers, ending where it stopped reading.
89
107
  * TypeScript's `type` forms are always read.
90
108
  */
91
- export declare function lexImportsExports(source: string): LexedStatement[];
109
+ export declare function lexImportsExports(source: string, options?: LexImportsExportsOptions): LexedStatement[];
110
+
111
+ /**
112
+ * A module's `import(…)` and `require(…)` calls and Vite's
113
+ * `import.meta.glob(…)`, at any depth, in source order, read without a
114
+ * parser: each call's offsets and its first argument, if it's a string or
115
+ * a template without `${…}`. Comments, strings, templates and regular
116
+ * expressions are skipped, as {@link lexStrings} skips them, and it never
117
+ * throws. Where {@link parseModule} accepts the module, they are its
118
+ * `ImportExpression`s, its calls of an identifier `require` and of
119
+ * `import.meta.glob`, and, in TypeScript, its `import("a")` types and
120
+ * `import a = require("a")`. A method named `import` or `require` isn't a
121
+ * call.
122
+ */
123
+ export declare function lexDynamicImports(source: string): LexedDynamicImport[];
92
124
 
93
125
  /**
94
126
  * A module's string literals and the text of its template literals, in
package/lexer.js CHANGED
@@ -1,3 +1,3 @@
1
- import{isDigit}from"./shared-5tpb3h6x.js";import{isWordCode,scan,scanLiterals,lineEnd,skipTrivia,isWordAt}from"./shared-y3nf00py.js";import"./shared-dgdrqgdn.js";import{lexComponent2}from"./shared-rce4ty8a.js";function lexImportsExports(source){let lexer=new Lexer(source),statements=[];return scan(source,!1,(_start,keyword)=>{let statement=lexer.statement(keyword);return statements.push(statement),statement.end}),statements}function lexStrings(source){let lexer=new Lexer(source),strings=[];return scanLiterals(source,(start,end,template)=>{let quote=template?0:1;strings.push({kind:template?"template":"string",value:lexer.cooked(start+quote,end-quote,template),start,end})}),strings}class Lexer{source;pos=0;end=0;escapeEnd=0;constructor(source){this.source=source}statement(keyword){this.pos=this.end=keyword+6;let statement={kind:this.source.charCodeAt(keyword)===105?"import":"export",start:keyword,end:0,source:null,typeOnly:!1,specifiers:[]};if(!(statement.kind==="import"?this.import(statement):this.export(statement)))statement.source=null,statement.specifiers=[];return statement.end=this.end,statement}import(statement){let module=this.string();if(module!==null)return statement.source=module,this.finish();if(this.isWord("type")){let next=this.peekAfter(4);if(next===123||next===42||isIdentifierStart(next)&&!this.isWordAfter(4,"from"))statement.typeOnly=!0,this.advance(4)}let{specifiers,typeOnly}=statement,next=this.at();if(next!==123&&next!==42){let start=this.pos,local=this.name();if(local===null)return!1;if(this.at()===61)return this.importEquals();if(specifiers.push({kind:"default",imported:"default",local,typeOnly,start,end:this.end}),!this.eat(44))return this.from(statement);next=this.at()}if(next===42){let start=this.pos;if(this.advance(1),!this.eatWord("as"))return!1;let local=this.name();if(local===null)return!1;return specifiers.push({kind:"namespace",imported:"*",local,typeOnly,start,end:this.end}),this.from(statement)}if(!this.eat(123))return!1;while(!this.eat(125)){let start=this.skip(),named=this.typeModifier()||typeOnly,name=this.name(),imported=name??this.string()?.value;if(imported===void 0)return!1;let local=name;if(this.eatWord("as"))local=this.name();if(local===null)return!1;if(specifiers.push({kind:"named",imported,local,typeOnly:named,start,end:this.end}),!this.eat(44)&&this.at()!==125)return!1}return this.from(statement)}export(statement){if(this.eatWord("import")){if(this.isWord("type")&&isIdentifierStart(this.peekAfter(4))&&!this.isWordAfter(4,"from"))statement.typeOnly=!0,this.advance(4);return this.name()!==null&&this.at()===61&&this.importEquals()}if(this.isWord("type")){let next=this.peekAfter(4);if(next===123||next===42)statement.typeOnly=!0,this.advance(4)}let{specifiers,typeOnly}=statement;if(this.at()===42){let start=this.pos;this.advance(1);let exported=null;if(this.eatWord("as")){if(exported=this.moduleExportName(),exported===null)return!1}return specifiers.push({kind:exported===null?"all":"namespace",local:"*",exported,typeOnly,start,end:this.end}),this.from(statement)}if(!this.eat(123))return!1;while(!this.eat(125)){let start=this.skip(),named=this.typeModifier()||typeOnly,local=this.moduleExportName();if(local===null)return!1;let exported=local;if(this.eatWord("as"))exported=this.moduleExportName();if(exported===null)return!1;if(specifiers.push({kind:"named",local,exported,typeOnly:named,start,end:this.end}),!this.eat(44)&&this.at()!==125)return!1}return this.from(statement)}typeModifier(){if(!this.isWord("type"))return!1;let next=this.peekAfter(4);if(next===34||next===39||isIdentifierStart(next)&&!this.isWordAfter(4,"as"))return this.advance(4),!0;return!1}importEquals(){if(this.advance(1),this.isWord("require")&&this.peekAfter(7)===40){if(this.advance(7),this.eat(40),this.string()===null||!this.eat(41))return!1}else do if(this.name()===null)return!1;while(this.eat(46));return this.eat(59),!0}from(statement){if(!this.eatWord("from"))return!1;return statement.source=this.string(),statement.source!==null&&this.finish()}finish(){let keyword=this.isWord("with")?4:0;if(this.isWord("assert")&&lineEnd(this.source,this.end)>=this.pos)keyword=6;if(keyword!==0&&this.peekAfter(keyword)===123){this.advance(keyword),this.eat(123);while(!this.eat(125))if(this.string()===null&&this.name()===null&&!this.eat(58)&&!this.eat(44))return!1}return this.eat(59),!0}skip(){return this.pos=skipTrivia(this.source,this.pos),this.pos}at(){return this.source.charCodeAt(this.skip())}advance(length){this.pos+=length,this.end=this.pos}peekAfter(length){return this.source.charCodeAt(skipTrivia(this.source,this.pos+length))}isWordAfter(length,word){return isWordAt(this.source,skipTrivia(this.source,this.pos+length),word)}eat(code){if(this.at()!==code)return!1;return this.advance(1),!0}isWord(word){return isWordAt(this.source,this.skip(),word)}eatWord(word){if(!this.isWord(word))return!1;return this.advance(word.length),!0}moduleExportName(){return this.name()??this.string()?.value??null}name(){let source=this.source,start=this.skip();if(!isWordCode(source.charCodeAt(start))||isDigit(source.charCodeAt(start)))return null;let value="",chunk=start,i=start;while(i<source.length){let code=source.charCodeAt(i);if(code===92){if(source.charCodeAt(i+1)!==117)return null;let escaped=this.unicodeEscape(i+2);if(escaped===null)return null;value+=source.slice(chunk,i)+escaped,i=chunk=this.escapeEnd}else if(isWordCode(code))i++;else break}return this.advance(i-start),value+source.slice(chunk,i)}string(){let source=this.source,start=this.skip(),quote=source.charCodeAt(start);if(quote!==34&&quote!==39)return null;let value="",chunk=start+1;for(let i=chunk;i<source.length;){let code=source.charCodeAt(i);if(code===quote)return this.advance(i+1-start),{value:value+source.slice(chunk,i),start,end:i+1};if(code===10||code===13)return null;if(code===92){let escaped=this.escape(i+1);if(escaped===null)return null;value+=source.slice(chunk,i)+escaped,i=chunk=this.escapeEnd}else i++}return null}cooked(from,to,template){let source=this.source,value="",chunk=from;for(let i=from;i<to;){let code=source.charCodeAt(i);if(code===92){let escaped=this.escape(i+1);if(escaped===null)return null;value+=source.slice(chunk,i)+escaped,i=chunk=this.escapeEnd}else if(code===13&&template)value+=`${source.slice(chunk,i)}
1
+ import{isDigit}from"./shared-5tpb3h6x.js";import{isWordCode,scan,scanLiterals,scanCalls,closingBracket,lineEnd,skipTrivia,isWordAt}from"./shared-e4gbs4rb.js";import"./shared-dgdrqgdn.js";import{lexComponent2}from"./shared-a23q4q40.js";function lexImportsExports(source,options={}){let lexer=new Lexer(source);lexer.exportLists=options.exportLists??!1;let statements=[];return scan(source,!1,(_start,keyword)=>{let statement=lexer.statement(keyword);return statements.push(statement),statement.end},lexer.exportLists),statements}function lexDynamicImports(source){let lexer=new Lexer(source),imports=[];return scanCalls(source,(start,member)=>{let call=lexer.dynamicImport(start,member);if(call!==null)imports.push(call)}),imports}function lexStrings(source){let lexer=new Lexer(source),strings=[];return scanLiterals(source,(start,end,template)=>{let quote=template?0:1;strings.push({kind:template?"template":"string",value:lexer.cooked(start+quote,end-quote,template),start,end})}),strings}class Lexer{source;pos=0;end=0;escapeEnd=0;exportLists=!1;constructor(source){this.source=source}statement(keyword){this.pos=this.end=keyword+6;let statement={kind:this.source.charCodeAt(keyword)===105?"import":"export",start:keyword,end:0,source:null,typeOnly:!1,specifiers:[]};if(!(statement.kind==="import"?this.import(statement):this.export(statement)))statement.source=null,statement.specifiers=[];return statement.end=this.end,statement}import(statement){let module=this.string();if(module!==null)return statement.source=module,this.finish();if(this.isWord("type")){let next=this.peekAfter(4);if(next===123||next===42||isIdentifierStart(next)&&!this.isWordAfter(4,"from"))statement.typeOnly=!0,this.advance(4)}let{specifiers,typeOnly}=statement,next=this.at();if(next!==123&&next!==42){let start=this.pos,local=this.name();if(local===null)return!1;if(this.at()===61)return this.importEquals();if(specifiers.push({kind:"default",imported:"default",local,typeOnly,start,end:this.end}),!this.eat(44))return this.from(statement);next=this.at()}if(next===42){let start=this.pos;if(this.advance(1),!this.eatWord("as"))return!1;let local=this.name();if(local===null)return!1;return specifiers.push({kind:"namespace",imported:"*",local,typeOnly,start,end:this.end}),this.from(statement)}if(!this.eat(123))return!1;while(!this.eat(125)){let start=this.skip(),named=this.typeModifier()||typeOnly,name=this.name(),imported=name??this.string()?.value;if(imported===void 0)return!1;let local=name;if(this.eatWord("as"))local=this.name();if(local===null)return!1;if(specifiers.push({kind:"named",imported,local,typeOnly:named,start,end:this.end}),!this.eat(44)&&this.at()!==125)return!1}return this.from(statement)}export(statement){if(this.eatWord("import")){if(this.isWord("type")&&isIdentifierStart(this.peekAfter(4))&&!this.isWordAfter(4,"from"))statement.typeOnly=!0,this.advance(4);return this.name()!==null&&this.at()===61&&this.importEquals()}if(this.isWord("type")){let next=this.peekAfter(4);if(next===123||next===42)statement.typeOnly=!0,this.advance(4)}let{specifiers,typeOnly}=statement;if(this.at()===42){let start=this.pos;this.advance(1);let exported=null;if(this.eatWord("as")){if(exported=this.moduleExportName(),exported===null)return!1}return specifiers.push({kind:exported===null?"all":"namespace",local:"*",exported,typeOnly,start,end:this.end}),this.from(statement)}if(!this.eat(123))return!1;while(!this.eat(125)){let start=this.skip(),named=this.typeModifier()||typeOnly,local=this.moduleExportName();if(local===null)return!1;let exported=local;if(this.eatWord("as"))exported=this.moduleExportName();if(exported===null)return!1;if(specifiers.push({kind:"named",local,exported,typeOnly:named,start,end:this.end}),!this.eat(44)&&this.at()!==125)return!1}if(this.exportLists&&!this.isWord("from")){for(let specifier of specifiers)specifier.kind="local";return this.eat(59),!0}return this.from(statement)}dynamicImport(start,member){let isImport=this.source.charCodeAt(start)===105;this.pos=this.end=start+(isImport?6:7);let kind=isImport?"import":"require";if(isImport&&this.eat(46)){if(!this.eatWord("meta")||!this.eat(46)||!this.eatWord("glob")||!this.typeArguments())return null;kind="glob"}if(!this.eat(40))return null;let argument=this.skip(),source=this.string()??this.template(),close=this.at()===41?this.pos:-1;if(close===-1){if(this.at()!==44)source=null;close=closingBracket(this.source,argument)}if(member&&kind!=="glob"){let after=this.source.charCodeAt(skipTrivia(this.source,close+1));if(after===123||after===58)return null}return{kind,source,start,end:Math.min(close+1,this.source.length)}}typeArguments(){if(this.at()!==60)return!0;let source=this.source,depth=0;for(let i=this.pos;i<source.length;i=skipTrivia(source,i+1)){let code=source.charCodeAt(i);if(code===34||code===39||code===96){let end=source.indexOf(source[i],i+1);if(end===-1)return!1;i=end}else if(code===60)depth++;else if(code===62&&source.charCodeAt(i-1)!==61){if(--depth===0)return this.advance(i+1-this.pos),!0}}return!1}template(){let source=this.source,start=this.skip();if(source.charCodeAt(start)!==96)return null;for(let i=start+1;i<source.length;i++){let code=source.charCodeAt(i);if(code===96){let value=this.cooked(start+1,i,!0);if(value===null)return null;return this.advance(i+1-start),{value,start,end:i+1}}if(code===92)i++;else if(code===36&&source.charCodeAt(i+1)===123)return null}return null}typeModifier(){if(!this.isWord("type"))return!1;let next=this.peekAfter(4);if(next===34||next===39||isIdentifierStart(next)&&!this.isWordAfter(4,"as"))return this.advance(4),!0;return!1}importEquals(){if(this.advance(1),this.isWord("require")&&this.peekAfter(7)===40){if(this.advance(7),this.eat(40),this.string()===null||!this.eat(41))return!1}else do if(this.name()===null)return!1;while(this.eat(46));return this.eat(59),!0}from(statement){if(!this.eatWord("from"))return!1;return statement.source=this.string(),statement.source!==null&&this.finish()}finish(){let keyword=this.isWord("with")?4:0;if(this.isWord("assert")&&lineEnd(this.source,this.end)>=this.pos)keyword=6;if(keyword!==0&&this.peekAfter(keyword)===123){this.advance(keyword),this.eat(123);while(!this.eat(125))if(this.string()===null&&this.name()===null&&!this.eat(58)&&!this.eat(44))return!1}return this.eat(59),!0}skip(){return this.pos=skipTrivia(this.source,this.pos),this.pos}at(){return this.source.charCodeAt(this.skip())}advance(length){this.pos+=length,this.end=this.pos}peekAfter(length){return this.source.charCodeAt(skipTrivia(this.source,this.pos+length))}isWordAfter(length,word){return isWordAt(this.source,skipTrivia(this.source,this.pos+length),word)}eat(code){if(this.at()!==code)return!1;return this.advance(1),!0}isWord(word){return isWordAt(this.source,this.skip(),word)}eatWord(word){if(!this.isWord(word))return!1;return this.advance(word.length),!0}moduleExportName(){return this.name()??this.string()?.value??null}name(){let source=this.source,start=this.skip();if(!isWordCode(source.charCodeAt(start))||isDigit(source.charCodeAt(start)))return null;let value="",chunk=start,i=start;while(i<source.length){let code=source.charCodeAt(i);if(code===92){if(source.charCodeAt(i+1)!==117)return null;let escaped=this.unicodeEscape(i+2);if(escaped===null)return null;value+=source.slice(chunk,i)+escaped,i=chunk=this.escapeEnd}else if(isWordCode(code))i++;else break}return this.advance(i-start),value+source.slice(chunk,i)}string(){let source=this.source,start=this.skip(),quote=source.charCodeAt(start);if(quote!==34&&quote!==39)return null;let value="",chunk=start+1;for(let i=chunk;i<source.length;){let code=source.charCodeAt(i);if(code===quote)return this.advance(i+1-start),{value:value+source.slice(chunk,i),start,end:i+1};if(code===10||code===13)return null;if(code===92){let escaped=this.escape(i+1);if(escaped===null)return null;value+=source.slice(chunk,i)+escaped,i=chunk=this.escapeEnd}else i++}return null}cooked(from,to,template){let source=this.source,value="",chunk=from;for(let i=from;i<to;){let code=source.charCodeAt(i);if(code===92){let escaped=this.escape(i+1);if(escaped===null)return null;value+=source.slice(chunk,i)+escaped,i=chunk=this.escapeEnd}else if(code===13&&template)value+=`${source.slice(chunk,i)}
2
2
  `,i+=source.charCodeAt(i+1)===10?2:1,chunk=i;else i++}return value+source.slice(chunk,to)}escape(pos){let code=this.source.charCodeAt(pos);switch(this.escapeEnd=pos+1,code){case 110:return`
3
- `;case 114:return"\r";case 116:return"\t";case 98:return"\b";case 118:return"\v";case 102:return"\f";case 48:return isDigit(this.source.charCodeAt(pos+1))?null:"\x00";case 120:return this.hexEscape(pos+1,2);case 117:return this.unicodeEscape(pos+1);case 13:if(this.source.charCodeAt(pos+1)===10)this.escapeEnd++;return"";case 10:case 8232:case 8233:return"";default:return isDigit(code)||pos>=this.source.length?null:String.fromCharCode(code)}}unicodeEscape(pos){if(this.source.charCodeAt(pos)!==123)return this.hexEscape(pos,4);let value=0,i=pos+1;for(;this.source.charCodeAt(i)!==125;i++){let digit=hexValue(this.source.charCodeAt(i));if(digit===-1)return null;if(value=value*16+digit,value>1114111)return null}if(i===pos+1)return null;return this.escapeEnd=i+1,String.fromCodePoint(value)}hexEscape(pos,length){let value=0;for(let i=pos;i<pos+length;i++){let digit=hexValue(this.source.charCodeAt(i));if(digit===-1)return null;value=value*16+digit}return this.escapeEnd=pos+length,String.fromCharCode(value)}}function isIdentifierStart(code){return code!==92&&isWordCode(code)&&!isDigit(code)}function hexValue(code){if(isDigit(code))return code-48;let lower=code|32;return lower>=97&&lower<=102?lower-87:-1}export{lexComponent2 as lexComponent,lexImportsExports,lexStrings};
3
+ `;case 114:return"\r";case 116:return"\t";case 98:return"\b";case 118:return"\v";case 102:return"\f";case 48:return isDigit(this.source.charCodeAt(pos+1))?null:"\x00";case 120:return this.hexEscape(pos+1,2);case 117:return this.unicodeEscape(pos+1);case 13:if(this.source.charCodeAt(pos+1)===10)this.escapeEnd++;return"";case 10:case 8232:case 8233:return"";default:return isDigit(code)||pos>=this.source.length?null:String.fromCharCode(code)}}unicodeEscape(pos){if(this.source.charCodeAt(pos)!==123)return this.hexEscape(pos,4);let value=0,i=pos+1;for(;this.source.charCodeAt(i)!==125;i++){let digit=hexValue(this.source.charCodeAt(i));if(digit===-1)return null;if(value=value*16+digit,value>1114111)return null}if(i===pos+1)return null;return this.escapeEnd=i+1,String.fromCodePoint(value)}hexEscape(pos,length){let value=0;for(let i=pos;i<pos+length;i++){let digit=hexValue(this.source.charCodeAt(i));if(digit===-1)return null;value=value*16+digit}return this.escapeEnd=pos+length,String.fromCharCode(value)}}function isIdentifierStart(code){return code!==92&&isWordCode(code)&&!isDigit(code)}function hexValue(code){if(isDigit(code))return code-48;let lower=code|32;return lower>=97&&lower<=102?lower-87:-1}export{lexComponent2 as lexComponent,lexDynamicImports,lexImportsExports,lexStrings};
package/module.js CHANGED
@@ -1 +1 @@
1
- import"./shared-2pngd0mg.js";import"./shared-m0dcdh24.js";import{ParseError2}from"./shared-nan648gn.js";import"./shared-5tpb3h6x.js";import"./shared-y3nf00py.js";import{parseModuleWith}from"./shared-z9y4mrek.js";import{parseImportsExportsWith}from"./shared-rvkvagj5.js";import{typeScriptParser}from"./shared-h6z1kjbb.js";function createModuleParser(support={}){let typescript=typeScriptParser(support.typescript);return{parseModule:(source,options={})=>parseModuleWith(source,options,typescript),parseImportsExports:(source,options={})=>parseImportsExportsWith(source,options,typescript)}}export{ParseError2 as ParseError,createModuleParser};
1
+ import"./shared-2pngd0mg.js";import"./shared-m0dcdh24.js";import{ParseError2}from"./shared-nan648gn.js";import"./shared-5tpb3h6x.js";import"./shared-e4gbs4rb.js";import{parseModuleWith}from"./shared-z9y4mrek.js";import{parseImportsExportsWith}from"./shared-tapcgcpr.js";import{typeScriptParser}from"./shared-h6z1kjbb.js";function createModuleParser(support={}){let typescript=typeScriptParser(support.typescript);return{parseModule:(source,options={})=>parseModuleWith(source,options,typescript),parseImportsExports:(source,options={})=>parseImportsExportsWith(source,options,typescript)}}export{ParseError2 as ParseError,createModuleParser};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sveast",
3
- "version": "0.9.5",
3
+ "version": "0.9.6",
4
4
  "license": "MIT",
5
5
  "description": "Fast, zero-dependency Svelte 5 parser with svelte/compiler's AST.",
6
6
  "author": "Eric Liu (https://github.com/metonym)",
@@ -1 +1 @@
1
- import"./shared-2pngd0mg.js";import"./shared-m0dcdh24.js";import"./shared-nan648gn.js";import"./shared-5tpb3h6x.js";import"./shared-y3nf00py.js";import"./shared-cs1ezg1f.js";import{TypeScriptParser}from"./shared-ke0fgd3r.js";import{parseImportsExportsWith}from"./shared-rvkvagj5.js";function parseImportsExports(source,options={}){return parseImportsExportsWith(source,options,TypeScriptParser)}export{parseImportsExports};
1
+ import"./shared-2pngd0mg.js";import"./shared-m0dcdh24.js";import"./shared-nan648gn.js";import"./shared-5tpb3h6x.js";import"./shared-e4gbs4rb.js";import"./shared-cs1ezg1f.js";import{TypeScriptParser}from"./shared-ke0fgd3r.js";import{parseImportsExportsWith}from"./shared-tapcgcpr.js";function parseImportsExports(source,options={}){return parseImportsExportsWith(source,options,TypeScriptParser)}export{parseImportsExports};
package/parse-sections.js CHANGED
@@ -1 +1 @@
1
- import{parseSections2}from"./shared-y41kz9tv.js";import"./shared-rce4ty8a.js";import"./shared-drb44hb9.js";import"./shared-ke0fgd3r.js";import"./shared-cs1ezg1f.js";import"./shared-xwzsb4m8.js";import"./shared-bzqbnvee.js";import"./shared-dgdrqgdn.js";import"./shared-y3nf00py.js";import"./shared-5tpb3h6x.js";import"./shared-nan648gn.js";import"./shared-m0dcdh24.js";import"./shared-2pngd0mg.js";export{parseSections2 as parseSections};
1
+ import{parseSections2}from"./shared-as9z0pac.js";import"./shared-a23q4q40.js";import"./shared-drb44hb9.js";import"./shared-ke0fgd3r.js";import"./shared-cs1ezg1f.js";import"./shared-xwzsb4m8.js";import"./shared-bzqbnvee.js";import"./shared-dgdrqgdn.js";import"./shared-e4gbs4rb.js";import"./shared-5tpb3h6x.js";import"./shared-nan648gn.js";import"./shared-m0dcdh24.js";import"./shared-2pngd0mg.js";export{parseSections2 as parseSections};
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-y3nf00py.js";import"./shared-m0dcdh24.js";import"./shared-2pngd0mg.js";import"./shared-nan648gn.js";import"./shared-bzqbnvee.js";import"./shared-xwzsb4m8.js";import"./shared-cs1ezg1f.js";import{parse2}from"./shared-qkp49nav.js";import{parseSections2}from"./shared-y41kz9tv.js";import{extractIdentifiers2,isReference2,STOP2,SKIP2,walk2}from"./shared-jpvd0875.js";import{RUNES,RUNE_NAMES}from"./shared-m3dr31c3.js";import{lexComponent2}from"./shared-rce4ty8a.js";import"./shared-drb44hb9.js";import"./shared-ke0fgd3r.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};
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-2pngd0mg.js";import"./shared-nan648gn.js";import"./shared-bzqbnvee.js";import"./shared-xwzsb4m8.js";import"./shared-cs1ezg1f.js";import{parse2}from"./shared-qkp49nav.js";import{parseSections2}from"./shared-as9z0pac.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-ke0fgd3r.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};
@@ -1,3 +1,3 @@
1
- import{closingTagOmitted}from"./shared-dgdrqgdn.js";import{withoutByteOrderMark,isWhitespace,skipWhitespace,isTypeScript,closingScriptTag,closingScriptTagEnd,isVoid,styleContentEnd,isQuote,nameEnd,endsUnquotedValue}from"./shared-5tpb3h6x.js";import{closingBracket}from"./shared-y3nf00py.js";var BLOCK="{",LT=60,GT=62,SLASH=47,EQUALS=61,BRACE=123,REGEX_CLOSING_STYLE_TAG_END=/\s*>/y,REGEX_CLOSING_TEXTAREA=/<\/textarea(\s[^>]*)?>/iy,SECTION_TAG_NAMES=["cript","tyle","velte:options"],CLOSING_OPTIONS_TAG="</svelte:options";function lexComponent2(input){let source=withoutByteOrderMark(input).trimEnd();return lex(source,isTypeScript(source),null)}function topLevelTags(source){let found={tags:[],comments:[]};return lex(source,!1,found),found}function lex(source,typescript,found){let component={typescript,instance:null,module:null,css:null,options:null},last=lastSectionTag(source),stack=[],i=0;while(i<=last){let code=source.charCodeAt(i);if(code===LT)i=readTag(source,i,stack,component,found);else if(code===BRACE)i=readMustache(source,i,stack);else i++}return component}function lastSectionTag(source){let last=-1,i=source.indexOf("<s");while(i!==-1){let end=sectionTagNameEnd(source,i+2);if(end!==-1){let code=source.charCodeAt(end);if(end===source.length||isWhitespace(code)||code===SLASH||code===GT)last=i}i=source.indexOf("<s",i+2)}return last}function sectionTagNameEnd(source,from){for(let name of SECTION_TAG_NAMES)if(source.startsWith(name,from))return from+name.length;return-1}function expressionEnd(source,from){return Math.min(closingBracket(source,from)+1,source.length)}function readMustache(source,start,stack){let i=skipWhitespace(source,start+1),code=source.charCodeAt(i),next=source.charCodeAt(i+1);if(code===35||code===58||code===64||code===SLASH&&next!==SLASH&&next!==42){i++;while(i<source.length){let letter=source.charCodeAt(i);if(letter<97||letter>122)break;i++}if(code===35)stack.push(BLOCK);else if(code===SLASH){let open=stack.lastIndexOf(BLOCK);if(open!==-1)stack.length=open}}return expressionEnd(source,i)}function readTag(source,start,stack,component,found){if(source.startsWith("!--",start+1)){let close=source.indexOf("-->",start+4),end=close===-1?source.length:close+3;if(found&&stack.length===0)found.comments.push(start,end);return end}if(source.charCodeAt(start+1)===SLASH){let nameStart=start+2,name=source.slice(nameStart,nameEnd(source,nameStart,!1)),open=stack.lastIndexOf(name);if(open!==-1)stack.length=open;return eatGreaterThan(source,skipWhitespace(source,nameStart+name.length))}let name=source.slice(start+1,nameEnd(source,start+1,!1)),i=skipWhitespace(source,start+1+name.length),parent=stack[stack.length-1];if(parent!==void 0&&closingTagOmitted(parent,name))stack.pop();let topLevel=stack.length===0;if(found&&topLevel&&(name==="script"||name==="style"||name==="svelte:options"))found.tags.push(start);if(topLevel&&(name==="script"||name==="style")){let attributes=[];if(i=eatGreaterThan(source,readStaticAttributes(source,i,attributes)),name==="script"){let script=readScript(source,start,i,attributes);if(script.context==="module")component.module??=script;else component.instance??=script;return script.end}let css=readStyle(source,start,i,attributes);return component.css??=css,css.end}let attributes=topLevel&&name==="svelte:options"?[]:null;if(i=readAttributes(source,i,attributes),source.charCodeAt(i)===SLASH||isVoid(name)){if(source.charCodeAt(i)===SLASH)i++;i=eatGreaterThan(source,i)}else{if(i=eatGreaterThan(source,i),name==="textarea")return textareaEnd(source,i);if(name==="script"||name==="style"){let closer=`</${name}>`,close=source.indexOf(closer,i);return close===-1?source.length:close+closer.length}if(attributes&&source.startsWith(CLOSING_OPTIONS_TAG,i))i=eatGreaterThan(source,skipWhitespace(source,i+CLOSING_OPTIONS_TAG.length));else return stack.push(name),i}if(attributes)component.options??={start,end:i,attributes};return i}function eatGreaterThan(source,i){return source.charCodeAt(i)===GT?i+1:i}function readScript(source,start,contentStart,attributes){let close=closingScriptTag(source,contentStart),contentEnd=close===-1?source.length:close,module=attributes.some((attribute)=>attribute.name==="module"||attribute.name==="context");return{start,end:close===-1?source.length:closingScriptTagEnd(source,close),context:module?"module":"default",attributes,content:{start:contentStart,end:contentEnd}}}function readStyle(source,start,contentStart,attributes){let contentEnd=styleContentEnd(source,contentStart),end=contentEnd;if(source.startsWith("</style",end)){end+=7,REGEX_CLOSING_STYLE_TAG_END.lastIndex=end;let close=REGEX_CLOSING_STYLE_TAG_END.exec(source);if(close)end+=close[0].length}return{start,end,attributes,content:{start:contentStart,end:contentEnd}}}function readStaticAttributes(source,from,into){let i=from;for(;;){let start=i,end=nameEnd(source,i,!0);if(end===start)return i;i=end;let value=!0;if(source.charCodeAt(i)===EQUALS){let at=skipWhitespace(source,i+1),quote=source.charCodeAt(at),valueEnd=-1;if(isQuote(quote)){let close=source.indexOf(source[at],at+1);if(close!==-1)valueEnd=close+1}if(valueEnd===-1){valueEnd=at;while(valueEnd<source.length&&source.charCodeAt(valueEnd)!==GT&&!isWhitespace(source.charCodeAt(valueEnd)))valueEnd++}let quotes=isQuote(quote)?1:0;value=source.slice(at+quotes,valueEnd-quotes),i=valueEnd}into.push({name:source.slice(start,end),value,start,end:i}),i=skipWhitespace(source,i)}}function readAttributes(source,from,into){let i=from;for(;;){for(;;){if(source.startsWith("/*",i)){let end=source.indexOf("*/",i+2);i=end===-1?source.length:end+2}else if(source.startsWith("//",i)){let end=source.indexOf(`
1
+ import{closingTagOmitted}from"./shared-dgdrqgdn.js";import{withoutByteOrderMark,isWhitespace,skipWhitespace,isTypeScript,closingScriptTag,closingScriptTagEnd,isVoid,styleContentEnd,isQuote,nameEnd,endsUnquotedValue}from"./shared-5tpb3h6x.js";import{closingBracket}from"./shared-e4gbs4rb.js";var BLOCK="{",LT=60,GT=62,SLASH=47,EQUALS=61,BRACE=123,REGEX_CLOSING_STYLE_TAG_END=/\s*>/y,REGEX_CLOSING_TEXTAREA=/<\/textarea(\s[^>]*)?>/iy,SECTION_TAG_NAMES=["cript","tyle","velte:options"],CLOSING_OPTIONS_TAG="</svelte:options";function lexComponent2(input){let source=withoutByteOrderMark(input).trimEnd();return lex(source,isTypeScript(source),null)}function topLevelTags(source){let found={tags:[],comments:[]};return lex(source,!1,found),found}function lex(source,typescript,found){let component={typescript,instance:null,module:null,css:null,options:null},last=lastSectionTag(source),stack=[],i=0;while(i<=last){let code=source.charCodeAt(i);if(code===LT)i=readTag(source,i,stack,component,found);else if(code===BRACE)i=readMustache(source,i,stack);else i++}return component}function lastSectionTag(source){let last=-1,i=source.indexOf("<s");while(i!==-1){let end=sectionTagNameEnd(source,i+2);if(end!==-1){let code=source.charCodeAt(end);if(end===source.length||isWhitespace(code)||code===SLASH||code===GT)last=i}i=source.indexOf("<s",i+2)}return last}function sectionTagNameEnd(source,from){for(let name of SECTION_TAG_NAMES)if(source.startsWith(name,from))return from+name.length;return-1}function expressionEnd(source,from){return Math.min(closingBracket(source,from)+1,source.length)}function readMustache(source,start,stack){let i=skipWhitespace(source,start+1),code=source.charCodeAt(i),next=source.charCodeAt(i+1);if(code===35||code===58||code===64||code===SLASH&&next!==SLASH&&next!==42){i++;while(i<source.length){let letter=source.charCodeAt(i);if(letter<97||letter>122)break;i++}if(code===35)stack.push(BLOCK);else if(code===SLASH){let open=stack.lastIndexOf(BLOCK);if(open!==-1)stack.length=open}}return expressionEnd(source,i)}function readTag(source,start,stack,component,found){if(source.startsWith("!--",start+1)){let close=source.indexOf("-->",start+4),end=close===-1?source.length:close+3;if(found&&stack.length===0)found.comments.push(start,end);return end}if(source.charCodeAt(start+1)===SLASH){let nameStart=start+2,name=source.slice(nameStart,nameEnd(source,nameStart,!1)),open=stack.lastIndexOf(name);if(open!==-1)stack.length=open;return eatGreaterThan(source,skipWhitespace(source,nameStart+name.length))}let name=source.slice(start+1,nameEnd(source,start+1,!1)),i=skipWhitespace(source,start+1+name.length),parent=stack[stack.length-1];if(parent!==void 0&&closingTagOmitted(parent,name))stack.pop();let topLevel=stack.length===0;if(found&&topLevel&&(name==="script"||name==="style"||name==="svelte:options"))found.tags.push(start);if(topLevel&&(name==="script"||name==="style")){let attributes=[];if(i=eatGreaterThan(source,readStaticAttributes(source,i,attributes)),name==="script"){let script=readScript(source,start,i,attributes);if(script.context==="module")component.module??=script;else component.instance??=script;return script.end}let css=readStyle(source,start,i,attributes);return component.css??=css,css.end}let attributes=topLevel&&name==="svelte:options"?[]:null;if(i=readAttributes(source,i,attributes),source.charCodeAt(i)===SLASH||isVoid(name)){if(source.charCodeAt(i)===SLASH)i++;i=eatGreaterThan(source,i)}else{if(i=eatGreaterThan(source,i),name==="textarea")return textareaEnd(source,i);if(name==="script"||name==="style"){let closer=`</${name}>`,close=source.indexOf(closer,i);return close===-1?source.length:close+closer.length}if(attributes&&source.startsWith(CLOSING_OPTIONS_TAG,i))i=eatGreaterThan(source,skipWhitespace(source,i+CLOSING_OPTIONS_TAG.length));else return stack.push(name),i}if(attributes)component.options??={start,end:i,attributes};return i}function eatGreaterThan(source,i){return source.charCodeAt(i)===GT?i+1:i}function readScript(source,start,contentStart,attributes){let close=closingScriptTag(source,contentStart),contentEnd=close===-1?source.length:close,module=attributes.some((attribute)=>attribute.name==="module"||attribute.name==="context");return{start,end:close===-1?source.length:closingScriptTagEnd(source,close),context:module?"module":"default",attributes,content:{start:contentStart,end:contentEnd}}}function readStyle(source,start,contentStart,attributes){let contentEnd=styleContentEnd(source,contentStart),end=contentEnd;if(source.startsWith("</style",end)){end+=7,REGEX_CLOSING_STYLE_TAG_END.lastIndex=end;let close=REGEX_CLOSING_STYLE_TAG_END.exec(source);if(close)end+=close[0].length}return{start,end,attributes,content:{start:contentStart,end:contentEnd}}}function readStaticAttributes(source,from,into){let i=from;for(;;){let start=i,end=nameEnd(source,i,!0);if(end===start)return i;i=end;let value=!0;if(source.charCodeAt(i)===EQUALS){let at=skipWhitespace(source,i+1),quote=source.charCodeAt(at),valueEnd=-1;if(isQuote(quote)){let close=source.indexOf(source[at],at+1);if(close!==-1)valueEnd=close+1}if(valueEnd===-1){valueEnd=at;while(valueEnd<source.length&&source.charCodeAt(valueEnd)!==GT&&!isWhitespace(source.charCodeAt(valueEnd)))valueEnd++}let quotes=isQuote(quote)?1:0;value=source.slice(at+quotes,valueEnd-quotes),i=valueEnd}into.push({name:source.slice(start,end),value,start,end:i}),i=skipWhitespace(source,i)}}function readAttributes(source,from,into){let i=from;for(;;){for(;;){if(source.startsWith("/*",i)){let end=source.indexOf("*/",i+2);i=end===-1?source.length:end+2}else if(source.startsWith("//",i)){let end=source.indexOf(`
2
2
  `,i+2);i=end===-1?source.length:end}else break;i=skipWhitespace(source,i)}let start=i;if(source.charCodeAt(i)===BRACE){i=skipWhitespace(source,expressionEnd(source,i+1));continue}let nameEndAt=nameEnd(source,i,!0);if(nameEndAt===start)return i;let end=nameEndAt,value=!0;if(i=skipWhitespace(source,nameEndAt),source.charCodeAt(i)===EQUALS){let at=skipWhitespace(source,i+1);end=source.startsWith("/>",at)?at+1:attributeValueEnd(source,at),value=isQuote(source.charCodeAt(at))?source.slice(at+1,Math.max(at+1,end-1)):source.slice(at,end),i=skipWhitespace(source,end)}into?.push({name:source.slice(start,nameEndAt),value,start,end})}}function attributeValueEnd(source,from){let quote=source.charCodeAt(from);if(isQuote(quote)){let i=from+1;while(i<source.length){let code=source.charCodeAt(i);if(code===quote)return i+1;i=code===BRACE?expressionEnd(source,i+1):i+1}return source.length}let i=from;while(i<source.length&&!endsUnquotedValue(source,i))i=source.charCodeAt(i)===BRACE?expressionEnd(source,i+1):i+1;return i}function textareaEnd(source,from){let i=from;while(i<source.length){let code=source.charCodeAt(i);if(code===LT){if(REGEX_CLOSING_TEXTAREA.lastIndex=i,REGEX_CLOSING_TEXTAREA.test(source))return REGEX_CLOSING_TEXTAREA.lastIndex}i=code===BRACE?expressionEnd(source,i+1):i+1}return source.length}
3
3
  export{lexComponent2,topLevelTags};
@@ -1,2 +1,2 @@
1
- import{decodeCharacterReferences}from"./shared-bzqbnvee.js";import{readElement,componentState,finishComponent,readNode}from"./shared-xwzsb4m8.js";import{topLevelTags}from"./shared-rce4ty8a.js";import{htmlEntityNames}from"./shared-drb44hb9.js";import{TypeScriptParser}from"./shared-ke0fgd3r.js";function parseComponentSections(source,options,support){let state=componentState(source,options,support);return readTopLevelTags(state),finishComponent(state)}function readTopLevelTags(state){let{source}=state,{tags,comments}=topLevelTags(source),nodes=state.root.fragment.nodes,appendText=(start,end)=>{if(end<=start)return;let raw=source.slice(start,end),data=raw.includes("<")||raw.includes("{")?raw:decodeCharacterReferences(raw,!1,state.entityNames);nodes.push({type:"Text",start,end,raw,data})},index=0,comment=0;for(let start of tags){for(;comment<comments.length&&comments[comment]<start;comment+=2){let commentStart=comments[comment];if(commentStart<index)continue;let end=comments[comment+1];appendText(index,commentStart),nodes.push({type:"Comment",start:commentStart,end,data:source.slice(commentStart+4,end-3)}),index=end}if(start<index)continue;appendText(index,start),state.index=start,readElement(state);while(state.stack.length>1&&state.index<source.length)readNode(state);index=state.index}let options=nodes.filter((node)=>node.type==="SvelteOptions");nodes.length=0,nodes.push(...options)}var support={typescript:TypeScriptParser,entityNames:htmlEntityNames};function parseSections2(source,options){return parseComponentSections(source,options,support)}
1
+ import{decodeCharacterReferences}from"./shared-bzqbnvee.js";import{readElement,componentState,finishComponent,readNode}from"./shared-xwzsb4m8.js";import{topLevelTags}from"./shared-a23q4q40.js";import{htmlEntityNames}from"./shared-drb44hb9.js";import{TypeScriptParser}from"./shared-ke0fgd3r.js";function parseComponentSections(source,options,support){let state=componentState(source,options,support);return readTopLevelTags(state),finishComponent(state)}function readTopLevelTags(state){let{source}=state,{tags,comments}=topLevelTags(source),nodes=state.root.fragment.nodes,appendText=(start,end)=>{if(end<=start)return;let raw=source.slice(start,end),data=raw.includes("<")||raw.includes("{")?raw:decodeCharacterReferences(raw,!1,state.entityNames);nodes.push({type:"Text",start,end,raw,data})},index=0,comment=0;for(let start of tags){for(;comment<comments.length&&comments[comment]<start;comment+=2){let commentStart=comments[comment];if(commentStart<index)continue;let end=comments[comment+1];appendText(index,commentStart),nodes.push({type:"Comment",start:commentStart,end,data:source.slice(commentStart+4,end-3)}),index=end}if(start<index)continue;appendText(index,start),state.index=start,readElement(state);while(state.stack.length>1&&state.index<source.length)readNode(state);index=state.index}let options=nodes.filter((node)=>node.type==="SvelteOptions");nodes.length=0,nodes.push(...options)}var support={typescript:TypeScriptParser,entityNames:htmlEntityNames};function parseSections2(source,options){return parseComponentSections(source,options,support)}
2
2
  export{parseSections2};
@@ -0,0 +1,3 @@
1
+ import{isDigit,isWhitespace}from"./shared-5tpb3h6x.js";var STATEMENT_START=0,OPERATOR=1,BLOCK_OPENER=2,VALUE=3,PAREN=0,HEAD_PAREN=1,BLOCK=2,OBJECT=3,TEMPLATE=4,HEAD=4,IMPORT=5,EXPORT=6,REQUIRE=7,KEYWORDS={await:OPERATOR,case:OPERATOR,default:OPERATOR,delete:OPERATOR,extends:OPERATOR,in:OPERATOR,instanceof:OPERATOR,new:OPERATOR,of:OPERATOR,return:OPERATOR,throw:OPERATOR,typeof:OPERATOR,void:OPERATOR,yield:OPERATOR,do:BLOCK_OPENER,else:BLOCK_OPENER,finally:BLOCK_OPENER,try:BLOCK_OPENER,for:HEAD,if:HEAD,while:HEAD,with:HEAD,import:IMPORT,export:EXPORT,require:REQUIRE},LONGEST_KEYWORD=10,KEYWORDS_BY_KEY=Array(keywordKey(128,0)).fill(null);for(let entry of Object.entries(KEYWORDS)){let key=keywordKey(entry[0].charCodeAt(0),entry[0].length),entries=KEYWORDS_BY_KEY[key]??[];entries.push(entry),KEYWORDS_BY_KEY[key]=entries}function keywordKey(first,length){return first*(LONGEST_KEYWORD+1)+length}function wordKind(source,start,end){let first=source.charCodeAt(start);if(first>=128||end-start>LONGEST_KEYWORD)return VALUE;let key=keywordKey(first,end-start),entries=KEYWORDS_BY_KEY[key];if(entries===null)return VALUE;for(let i=0;i<entries.length;i++)if(source.startsWith(entries[i][0],start))return entries[i][1];return VALUE}var ASCII_WORD=new Uint8Array(128);for(let range of["az","AZ","09","__","$$","\\\\"])for(let code=range.charCodeAt(0);code<=range.charCodeAt(1);code++)ASCII_WORD[code]=1;function isWordCode(code){return code>=128?!isWhitespace(code):ASCII_WORD[code]===1}function scan(source,localExports,parseAt,exportLists=!1){tokenize(source,lastStatementKeyword(source,localExports,exportLists),localExports,exportLists,parseAt,void 0,void 0)}function scanLiterals(source,literal){tokenize(source,source.length-1,!1,!1,void 0,literal,void 0)}function scanCalls(source,call){tokenize(source,source.length-1,!1,!1,void 0,void 0,call)}function tokenize(source,last,localExports,exportLists,parseAt,literal,call){let stack=[],pos=source.startsWith("#!")?lineEnd(source,2):0,prev=STATEMENT_START,afterDot=!1,head=!1,decorators=-1,statementEnd=()=>{if(prev=STATEMENT_START,stack.length===0)decorators=-1};while(pos<=last){let code=source.charCodeAt(pos);if(code===32||code===10||isWhitespace(code)){pos++;continue}if(code===47){let end=commentEnd(source,pos);if(end!==-1){pos=end;continue}}let wasAfterDot=afterDot,wasHead=head;if(afterDot=!1,head=!1,isWordCode(code)||code===35){let start=pos;pos=wordEnd(source,pos+1);let kind=wasAfterDot?VALUE:wordKind(source,start,pos);if(call!==void 0&&(kind===IMPORT||kind===REQUIRE))call(start,prev===STATEMENT_START||prev===VALUE);if(parseAt!==void 0&&stack.length===0&&(kind===EXPORT?localExports||isReexport(source,pos,exportLists):kind===IMPORT&&isImportDeclaration(source,pos)))pos=Math.max(pos,parseAt(decorators!==-1&&kind===EXPORT?decorators:start,start)),statementEnd();else if(kind===EXPORT)prev=BLOCK_OPENER;else if(kind===HEAD)head=!0,prev=VALUE;else prev=kind===OPERATOR||kind===BLOCK_OPENER?kind:VALUE;continue}switch(pos++,code){case 34:case 39:{let start=pos-1;pos=stringEnd(source,pos,code),literal?.(start,pos,!1),prev=VALUE;break}case 96:{let start=pos;pos=templateEnd(source,pos,stack),literal?.(start,quasiEnd(source,pos),!0),prev=source.charCodeAt(pos-1)===123?OPERATOR:VALUE;break}case 47:{let end=prev===VALUE?-1:regexEnd(source,pos);if(end===-1)prev=OPERATOR;else pos=wordCodesEnd(source,end),prev=VALUE;break}case 40:stack.push(wasHead?HEAD_PAREN:PAREN),prev=OPERATOR;break;case 41:prev=stack.pop()===HEAD_PAREN?BLOCK_OPENER:VALUE;break;case 123:stack.push(prev===OPERATOR?OBJECT:BLOCK),prev=STATEMENT_START;break;case 125:{let open=stack.pop();if(open===TEMPLATE){let start=pos;pos=templateEnd(source,pos,stack),literal?.(start,quasiEnd(source,pos),!0),prev=source.charCodeAt(pos-1)===123?OPERATOR:VALUE}else if(open===OBJECT)prev=VALUE;else statementEnd();break}case 59:statementEnd();break;case 44:prev=stack[stack.length-1]===OBJECT?STATEMENT_START:OPERATOR;break;case 93:prev=VALUE;break;case 46:if(isDigit(source.charCodeAt(pos)))pos=wordCodesEnd(source,pos),prev=VALUE;else if(source.startsWith("..",pos))pos+=2,prev=OPERATOR;else afterDot=!0,prev=OPERATOR;break;case 63:if(source.charCodeAt(pos)===46&&!isDigit(source.charCodeAt(pos+1)))pos++,afterDot=!0;prev=OPERATOR;break;case 33:prev=prev===VALUE&&!isWhitespace(source.charCodeAt(pos-2))?VALUE:OPERATOR;break;case 43:case 45:if(source.charCodeAt(pos)===code&&prev===VALUE)pos++;else prev=OPERATOR;break;case 61:if(prev=source.charCodeAt(pos)===62?BLOCK_OPENER:OPERATOR,prev===BLOCK_OPENER)pos++;break;case 64:if(stack.length===0&&decorators===-1)decorators=pos-1;prev=OPERATOR;break;default:prev=OPERATOR}}}function closingBracket(source,from,word){let length=source.length,stack=[],pos=from,prev=OPERATOR,afterDot=!1;while(pos<length){let code=source.charCodeAt(pos);if(code===32||code===10||isWhitespace(code)){pos++;continue}if(code===47){let end=commentEnd(source,pos);if(end!==-1){pos=end;continue}}let wasAfterDot=afterDot;if(afterDot=!1,isWordCode(code)||code===35){let start=pos;if(pos=wordEnd(source,pos+1),!wasAfterDot&&word?.(start,pos))return-1;let kind=wasAfterDot?VALUE:wordKind(source,start,pos);prev=kind===OPERATOR||kind===BLOCK_OPENER||kind===HEAD?OPERATOR:VALUE;continue}switch(pos++,code){case 34:case 39:pos=stringEnd(source,pos,code),prev=VALUE;break;case 96:pos=templateEnd(source,pos,stack),prev=source.charCodeAt(pos-1)===123?OPERATOR:VALUE;break;case 47:{let end=prev===VALUE?-1:regexEnd(source,pos);if(end===-1)prev=OPERATOR;else pos=wordCodesEnd(source,end),prev=VALUE;break}case 40:stack.push(PAREN),prev=OPERATOR;break;case 41:if(stack.length===0)return pos-1;stack.pop(),prev=VALUE;break;case 123:stack.push(prev===OPERATOR?OBJECT:BLOCK),prev=STATEMENT_START;break;case 125:{if(stack.length===0)return pos-1;let open=stack.pop();if(open===TEMPLATE)pos=templateEnd(source,pos,stack),prev=source.charCodeAt(pos-1)===123?OPERATOR:VALUE;else prev=open===OBJECT?VALUE:STATEMENT_START;break}case 93:prev=VALUE;break;case 46:if(isDigit(source.charCodeAt(pos)))pos=wordCodesEnd(source,pos),prev=VALUE;else if(source.startsWith("..",pos))pos+=2,prev=OPERATOR;else afterDot=!0,prev=OPERATOR;break;case 63:if(source.charCodeAt(pos)===46&&!isDigit(source.charCodeAt(pos+1)))pos++,afterDot=!0;prev=OPERATOR;break;case 33:prev=prev===VALUE&&!isWhitespace(source.charCodeAt(pos-2))?VALUE:OPERATOR;break;case 43:case 45:if(source.charCodeAt(pos)===code&&prev===VALUE)pos++;else prev=OPERATOR;break;case 61:if(source.charCodeAt(pos)===62)pos++;prev=OPERATOR;break;default:prev=OPERATOR}}return length}function isLineBreak(code){return code===10||code===13||code===8232||code===8233}function lineEnd(source,pos){for(let i=pos;i<source.length;i++)if(isLineBreak(source.charCodeAt(i)))return i;return source.length}function commentEnd(source,slash){let next=source.charCodeAt(slash+1);if(next===47)return lineEnd(source,slash+2);if(next!==42)return-1;let end=source.indexOf("*/",slash+2);return end===-1?source.length:end+2}function wordEnd(source,pos){let i=pos;while(i<source.length){let code=source.charCodeAt(i);if(code===92)i+=2;else if(isWordCode(code))i++;else break}return i}function wordCodesEnd(source,pos){let i=pos;while(i<source.length&&isWordCode(source.charCodeAt(i)))i++;return i}function stringEnd(source,pos,quote){for(let i=pos;i<source.length;i++){let code=source.charCodeAt(i);if(code===quote)return i+1;if(code===92)i+=source.startsWith(`\r
2
+ `,i+1)?2:1;else if(code===10||code===13)return i}return source.length}function templateEnd(source,pos,stack){for(let i=pos;i<source.length;i++){let code=source.charCodeAt(i);if(code===96)return i+1;if(code===92)i++;else if(code===36&&source.charCodeAt(i+1)===123)return stack.push(TEMPLATE),i+2}return source.length}function quasiEnd(source,pos){let code=source.charCodeAt(pos-1);if(code===96)return pos-1;if(code===123&&source.charCodeAt(pos-2)===36)return pos-2;return pos}function regexEnd(source,pos){let inClass=!1;for(let i=pos;i<source.length;i++){let code=source.charCodeAt(i);if(isLineBreak(code))return-1;if(code===92)i++;else if(code===91)inClass=!0;else if(code===93)inClass=!1;else if(code===47&&!inClass)return i+1}return-1}function skipTrivia(source,pos){let i=pos;while(i<source.length){let code=source.charCodeAt(i);if(isWhitespace(code)){i++;continue}let end=code===47?commentEnd(source,i):-1;if(end===-1)return i;i=end}return source.length}function isWordAt(source,pos,word){return source.charCodeAt(pos)===word.charCodeAt(0)&&source.startsWith(word,pos)&&!isWordCode(source.charCodeAt(pos+word.length))}function isImportDeclaration(source,pos){let code=source.charCodeAt(skipTrivia(source,pos));return code!==40&&code!==46}function isReexport(source,pos,lists){let i=skipTrivia(source,pos);if(isWordAt(source,i,"import"))return!0;if(isWordAt(source,i,"type"))i=skipTrivia(source,i+4);let code=source.charCodeAt(i);if(code===42)return!0;if(code!==123)return!1;if(lists)return!0;for(i++;i<source.length;i++){let inner=source.charCodeAt(i);if(inner===125)break;if(inner===34||inner===39)i=stringEnd(source,i+1,inner)-1;else if(inner===47)i=Math.max(i,skipTrivia(source,i)-1)}return isWordAt(source,skipTrivia(source,i+1),"from")}var STATEMENT_KEYWORD=/import|export/g;function lastStatementKeyword(source,localExports,exportLists){let last=-1;STATEMENT_KEYWORD.lastIndex=0;for(let match=STATEMENT_KEYWORD.exec(source);match!==null;match=STATEMENT_KEYWORD.exec(source)){let start=match.index,end=start+6;if(!isWordCode(source.charCodeAt(start-1))&&!isWordCode(source.charCodeAt(end))&&(source.charCodeAt(start)===105?isImportDeclaration(source,end):localExports||isReexport(source,end,exportLists)))last=start}return last}
3
+ export{isWordCode,scan,scanLiterals,scanCalls,closingBracket,lineEnd,wordCodesEnd,skipTrivia,isWordAt};
@@ -1,2 +1,2 @@
1
- import{setSource}from"./shared-m0dcdh24.js";import{parseStatementsAt}from"./shared-nan648gn.js";import{scan}from"./shared-y3nf00py.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))}
1
+ import{setSource}from"./shared-m0dcdh24.js";import{parseStatementsAt}from"./shared-nan648gn.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,3 +0,0 @@
1
- import{isDigit,isWhitespace}from"./shared-5tpb3h6x.js";var STATEMENT_START=0,OPERATOR=1,BLOCK_OPENER=2,VALUE=3,PAREN=0,HEAD_PAREN=1,BLOCK=2,OBJECT=3,TEMPLATE=4,HEAD=4,IMPORT=5,EXPORT=6,KEYWORDS={await:OPERATOR,case:OPERATOR,default:OPERATOR,delete:OPERATOR,extends:OPERATOR,in:OPERATOR,instanceof:OPERATOR,new:OPERATOR,of:OPERATOR,return:OPERATOR,throw:OPERATOR,typeof:OPERATOR,void:OPERATOR,yield:OPERATOR,do:BLOCK_OPENER,else:BLOCK_OPENER,finally:BLOCK_OPENER,try:BLOCK_OPENER,for:HEAD,if:HEAD,while:HEAD,with:HEAD,import:IMPORT,export:EXPORT},LONGEST_KEYWORD=10,KEYWORDS_BY_KEY=Array(keywordKey(128,0)).fill(null);for(let entry of Object.entries(KEYWORDS)){let key=keywordKey(entry[0].charCodeAt(0),entry[0].length),entries=KEYWORDS_BY_KEY[key]??[];entries.push(entry),KEYWORDS_BY_KEY[key]=entries}function keywordKey(first,length){return first*(LONGEST_KEYWORD+1)+length}function wordKind(source,start,end){let first=source.charCodeAt(start);if(first>=128||end-start>LONGEST_KEYWORD)return VALUE;let key=keywordKey(first,end-start),entries=KEYWORDS_BY_KEY[key];if(entries===null)return VALUE;for(let i=0;i<entries.length;i++)if(source.startsWith(entries[i][0],start))return entries[i][1];return VALUE}var ASCII_WORD=new Uint8Array(128);for(let range of["az","AZ","09","__","$$","\\\\"])for(let code=range.charCodeAt(0);code<=range.charCodeAt(1);code++)ASCII_WORD[code]=1;function isWordCode(code){return code>=128?!isWhitespace(code):ASCII_WORD[code]===1}function scan(source,localExports,parseAt){tokenize(source,lastStatementKeyword(source,localExports),localExports,parseAt,void 0)}function scanLiterals(source,literal){tokenize(source,source.length-1,!1,void 0,literal)}function tokenize(source,last,localExports,parseAt,literal){let stack=[],pos=source.startsWith("#!")?lineEnd(source,2):0,prev=STATEMENT_START,afterDot=!1,head=!1,decorators=-1,statementEnd=()=>{if(prev=STATEMENT_START,stack.length===0)decorators=-1};while(pos<=last){let code=source.charCodeAt(pos);if(code===32||code===10||isWhitespace(code)){pos++;continue}if(code===47){let end=commentEnd(source,pos);if(end!==-1){pos=end;continue}}let wasAfterDot=afterDot,wasHead=head;if(afterDot=!1,head=!1,isWordCode(code)||code===35){let start=pos;pos=wordEnd(source,pos+1);let kind=wasAfterDot?VALUE:wordKind(source,start,pos);if(parseAt!==void 0&&stack.length===0&&(kind===EXPORT?localExports||isReexport(source,pos):kind===IMPORT&&isImportDeclaration(source,pos)))pos=Math.max(pos,parseAt(decorators!==-1&&kind===EXPORT?decorators:start,start)),statementEnd();else if(kind===EXPORT)prev=BLOCK_OPENER;else if(kind===HEAD)head=!0,prev=VALUE;else prev=kind===OPERATOR||kind===BLOCK_OPENER?kind:VALUE;continue}switch(pos++,code){case 34:case 39:{let start=pos-1;pos=stringEnd(source,pos,code),literal?.(start,pos,!1),prev=VALUE;break}case 96:{let start=pos;pos=templateEnd(source,pos,stack),literal?.(start,quasiEnd(source,pos),!0),prev=source.charCodeAt(pos-1)===123?OPERATOR:VALUE;break}case 47:{let end=prev===VALUE?-1:regexEnd(source,pos);if(end===-1)prev=OPERATOR;else pos=wordCodesEnd(source,end),prev=VALUE;break}case 40:stack.push(wasHead?HEAD_PAREN:PAREN),prev=OPERATOR;break;case 41:prev=stack.pop()===HEAD_PAREN?BLOCK_OPENER:VALUE;break;case 123:stack.push(prev===OPERATOR?OBJECT:BLOCK),prev=STATEMENT_START;break;case 125:{let open=stack.pop();if(open===TEMPLATE){let start=pos;pos=templateEnd(source,pos,stack),literal?.(start,quasiEnd(source,pos),!0),prev=source.charCodeAt(pos-1)===123?OPERATOR:VALUE}else if(open===OBJECT)prev=VALUE;else statementEnd();break}case 59:statementEnd();break;case 93:prev=VALUE;break;case 46:if(isDigit(source.charCodeAt(pos)))pos=wordCodesEnd(source,pos),prev=VALUE;else if(source.startsWith("..",pos))pos+=2,prev=OPERATOR;else afterDot=!0,prev=OPERATOR;break;case 63:if(source.charCodeAt(pos)===46&&!isDigit(source.charCodeAt(pos+1)))pos++,afterDot=!0;prev=OPERATOR;break;case 33:prev=prev===VALUE&&!isWhitespace(source.charCodeAt(pos-2))?VALUE:OPERATOR;break;case 43:case 45:if(source.charCodeAt(pos)===code&&prev===VALUE)pos++;else prev=OPERATOR;break;case 61:if(prev=source.charCodeAt(pos)===62?BLOCK_OPENER:OPERATOR,prev===BLOCK_OPENER)pos++;break;case 64:if(stack.length===0&&decorators===-1)decorators=pos-1;prev=OPERATOR;break;default:prev=OPERATOR}}}function closingBracket(source,from,word){let length=source.length,stack=[],pos=from,prev=OPERATOR,afterDot=!1;while(pos<length){let code=source.charCodeAt(pos);if(code===32||code===10||isWhitespace(code)){pos++;continue}if(code===47){let end=commentEnd(source,pos);if(end!==-1){pos=end;continue}}let wasAfterDot=afterDot;if(afterDot=!1,isWordCode(code)||code===35){let start=pos;if(pos=wordEnd(source,pos+1),!wasAfterDot&&word?.(start,pos))return-1;let kind=wasAfterDot?VALUE:wordKind(source,start,pos);prev=kind===OPERATOR||kind===BLOCK_OPENER||kind===HEAD?OPERATOR:VALUE;continue}switch(pos++,code){case 34:case 39:pos=stringEnd(source,pos,code),prev=VALUE;break;case 96:pos=templateEnd(source,pos,stack),prev=source.charCodeAt(pos-1)===123?OPERATOR:VALUE;break;case 47:{let end=prev===VALUE?-1:regexEnd(source,pos);if(end===-1)prev=OPERATOR;else pos=wordCodesEnd(source,end),prev=VALUE;break}case 40:stack.push(PAREN),prev=OPERATOR;break;case 41:if(stack.length===0)return pos-1;stack.pop(),prev=VALUE;break;case 123:stack.push(prev===OPERATOR?OBJECT:BLOCK),prev=STATEMENT_START;break;case 125:{if(stack.length===0)return pos-1;let open=stack.pop();if(open===TEMPLATE)pos=templateEnd(source,pos,stack),prev=source.charCodeAt(pos-1)===123?OPERATOR:VALUE;else prev=open===OBJECT?VALUE:STATEMENT_START;break}case 93:prev=VALUE;break;case 46:if(isDigit(source.charCodeAt(pos)))pos=wordCodesEnd(source,pos),prev=VALUE;else if(source.startsWith("..",pos))pos+=2,prev=OPERATOR;else afterDot=!0,prev=OPERATOR;break;case 63:if(source.charCodeAt(pos)===46&&!isDigit(source.charCodeAt(pos+1)))pos++,afterDot=!0;prev=OPERATOR;break;case 33:prev=prev===VALUE&&!isWhitespace(source.charCodeAt(pos-2))?VALUE:OPERATOR;break;case 43:case 45:if(source.charCodeAt(pos)===code&&prev===VALUE)pos++;else prev=OPERATOR;break;case 61:if(source.charCodeAt(pos)===62)pos++;prev=OPERATOR;break;default:prev=OPERATOR}}return length}function isLineBreak(code){return code===10||code===13||code===8232||code===8233}function lineEnd(source,pos){for(let i=pos;i<source.length;i++)if(isLineBreak(source.charCodeAt(i)))return i;return source.length}function commentEnd(source,slash){let next=source.charCodeAt(slash+1);if(next===47)return lineEnd(source,slash+2);if(next!==42)return-1;let end=source.indexOf("*/",slash+2);return end===-1?source.length:end+2}function wordEnd(source,pos){let i=pos;while(i<source.length){let code=source.charCodeAt(i);if(code===92)i+=2;else if(isWordCode(code))i++;else break}return i}function wordCodesEnd(source,pos){let i=pos;while(i<source.length&&isWordCode(source.charCodeAt(i)))i++;return i}function stringEnd(source,pos,quote){for(let i=pos;i<source.length;i++){let code=source.charCodeAt(i);if(code===quote)return i+1;if(code===92)i+=source.startsWith(`\r
2
- `,i+1)?2:1;else if(code===10||code===13)return i}return source.length}function templateEnd(source,pos,stack){for(let i=pos;i<source.length;i++){let code=source.charCodeAt(i);if(code===96)return i+1;if(code===92)i++;else if(code===36&&source.charCodeAt(i+1)===123)return stack.push(TEMPLATE),i+2}return source.length}function quasiEnd(source,pos){let code=source.charCodeAt(pos-1);if(code===96)return pos-1;if(code===123&&source.charCodeAt(pos-2)===36)return pos-2;return pos}function regexEnd(source,pos){let inClass=!1;for(let i=pos;i<source.length;i++){let code=source.charCodeAt(i);if(isLineBreak(code))return-1;if(code===92)i++;else if(code===91)inClass=!0;else if(code===93)inClass=!1;else if(code===47&&!inClass)return i+1}return-1}function skipTrivia(source,pos){let i=pos;while(i<source.length){let code=source.charCodeAt(i);if(isWhitespace(code)){i++;continue}let end=code===47?commentEnd(source,i):-1;if(end===-1)return i;i=end}return source.length}function isWordAt(source,pos,word){return source.charCodeAt(pos)===word.charCodeAt(0)&&source.startsWith(word,pos)&&!isWordCode(source.charCodeAt(pos+word.length))}function isImportDeclaration(source,pos){let code=source.charCodeAt(skipTrivia(source,pos));return code!==40&&code!==46}function isReexport(source,pos){let i=skipTrivia(source,pos);if(isWordAt(source,i,"import"))return!0;if(isWordAt(source,i,"type"))i=skipTrivia(source,i+4);let code=source.charCodeAt(i);if(code===42)return!0;if(code!==123)return!1;for(i++;i<source.length;i++){let inner=source.charCodeAt(i);if(inner===125)break;if(inner===34||inner===39)i=stringEnd(source,i+1,inner)-1;else if(inner===47)i=Math.max(i,skipTrivia(source,i)-1)}return isWordAt(source,skipTrivia(source,i+1),"from")}var STATEMENT_KEYWORD=/import|export/g;function lastStatementKeyword(source,localExports){let last=-1;STATEMENT_KEYWORD.lastIndex=0;for(let match=STATEMENT_KEYWORD.exec(source);match!==null;match=STATEMENT_KEYWORD.exec(source)){let start=match.index,end=start+6;if(!isWordCode(source.charCodeAt(start-1))&&!isWordCode(source.charCodeAt(end))&&(source.charCodeAt(start)===105?isImportDeclaration(source,end):localExports||isReexport(source,end)))last=start}return last}
3
- export{isWordCode,scan,scanLiterals,closingBracket,lineEnd,wordCodesEnd,skipTrivia,isWordAt};