@tsrx/core 0.1.47 → 0.1.49

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/types/parse.d.ts CHANGED
@@ -420,6 +420,8 @@ export namespace Parse {
420
420
  export interface AcornTypeScriptExtensions {
421
421
  tokTypes: AcornTypeScriptTokTypes;
422
422
  tokContexts: AcornTypeScriptTokContexts;
423
+ /** Whether a token type can start/continue an identifier (incl. TS soft keywords) */
424
+ tokenIsIdentifier(token: TokenType): boolean;
423
425
  }
424
426
 
425
427
  export interface AcornTypeScriptFunctionBodyConfig {
@@ -427,6 +429,31 @@ export namespace Parse {
427
429
  isClassMethod?: boolean;
428
430
  }
429
431
 
432
+ /**
433
+ * Snapshot of tokenizer state returned by `lookahead()`, mirroring
434
+ * @sveltejs/acorn-typescript's saved lookahead state. Callers inspect the
435
+ * upcoming token (`type`/`value`/`start`/`containsEsc`) without consuming it,
436
+ * and pass the snapshot to the `*WithState` contextual helpers.
437
+ */
438
+ export interface LookaheadState {
439
+ pos: number;
440
+ type: TokenType;
441
+ value: string | number | RegExp | bigint | null;
442
+ start: number;
443
+ end: number;
444
+ startLoc: AST.Position;
445
+ endLoc: AST.Position;
446
+ lastTokEnd: number;
447
+ lastTokStart: number;
448
+ lastTokStartLoc: AST.Position;
449
+ lastTokEndLoc: AST.Position;
450
+ context: TokContext[];
451
+ curLine: number;
452
+ lineStart: number;
453
+ curPosition: () => AST.Position;
454
+ containsEsc: boolean;
455
+ }
456
+
430
457
  interface Scope {
431
458
  flags: number;
432
459
  var: string[];
@@ -496,6 +523,11 @@ export namespace Parse {
496
523
  inFunction: boolean;
497
524
  /** Whether @sveltejs/acorn-typescript is currently parsing a TypeScript type */
498
525
  inType: boolean;
526
+ /**
527
+ * `value`/`type` kind of the import or export declaration currently being
528
+ * parsed (@sveltejs/acorn-typescript). `undefined` when not inside one.
529
+ */
530
+ importOrExportOuterKind?: 'value' | 'type';
499
531
  /** Stack of label names for break/continue statements */
500
532
  labels: Array<{ kind: string | null; name?: string; statementStart?: number }>;
501
533
  /** Current scope flags stack */
@@ -756,6 +788,23 @@ export namespace Parse {
756
788
  */
757
789
  expectContextual(name: string): void;
758
790
 
791
+ /**
792
+ * Like `isContextual`, but tests a `lookahead()` snapshot instead of the
793
+ * current token (@sveltejs/acorn-typescript).
794
+ * @param keyword Keyword to check (e.g. "from", "defer")
795
+ * @param state Lookahead snapshot to test
796
+ */
797
+ isContextualWithState(keyword: string, state: LookaheadState): boolean;
798
+
799
+ /**
800
+ * If `state` is the contextual keyword `name`, consume `nextCount` tokens
801
+ * and return true (@sveltejs/acorn-typescript).
802
+ * @param name Contextual keyword to eat (e.g. "type", "defer")
803
+ * @param nextCount Number of tokens to advance when it matches
804
+ * @param state Lookahead snapshot to test
805
+ */
806
+ ts_eatContextualWithState(name: string, nextCount: number, state: LookaheadState): boolean;
807
+
759
808
  /**
760
809
  * Check if semicolon can be inserted at current position (ASI)
761
810
  */
@@ -831,10 +880,11 @@ export namespace Parse {
831
880
  // Lookahead
832
881
  // ============================================================
833
882
  /**
834
- * Look ahead one token without consuming
835
- * @returns Object with type and value of next token
883
+ * Look ahead `number` tokens (default 1) without consuming, returning a
884
+ * snapshot of the tokenizer state at that position.
885
+ * @param number How many tokens to look ahead (default 1)
836
886
  */
837
- lookahead(): { type: TokenType; value: any };
887
+ lookahead(number?: number): LookaheadState;
838
888
 
839
889
  /**
840
890
  * Get next token start position
@@ -1461,7 +1511,17 @@ export namespace Parse {
1461
1511
  // Module Parsing (Import/Export)
1462
1512
  // ============================================================
1463
1513
  /** Parse import declaration */
1464
- parseImport(node: AST.Node): AST.ImportDeclaration;
1514
+ parseImport(node: AST.TSRXImportDeclaration): AST.TSRXImportDeclaration;
1515
+
1516
+ /**
1517
+ * Parse a TypeScript import-equals declaration, `import x = require('y')`
1518
+ * or `import x = A.B` (@sveltejs/acorn-typescript). Typed as
1519
+ * `ImportDeclaration` because estree has no `TSImportEqualsDeclaration`.
1520
+ */
1521
+ tsParseImportEqualsDeclaration(node: AST.Node, isExport?: boolean): AST.ImportDeclaration;
1522
+
1523
+ /** Parse an optional import-attributes clause (`with { … }` / `assert { … }`) */
1524
+ parseMaybeImportAttributes(node: AST.Node): void;
1465
1525
 
1466
1526
  /** Parse import specifiers */
1467
1527
  parseImportSpecifiers(): AST.ImportSpecifier[];
@@ -1617,8 +1677,7 @@ export namespace Parse {
1617
1677
  * Parse JSX namespaced name (ns:name)
1618
1678
  */
1619
1679
  jsx_parseNamespacedName():
1620
- | ESTreeJSX.JSXNamespacedName
1621
- | ReturnType<Parser['jsx_parseIdentifier']>;
1680
+ ESTreeJSX.JSXNamespacedName | ReturnType<Parser['jsx_parseIdentifier']>;
1622
1681
 
1623
1682
  /**
1624
1683
  * Parse JSX element name (identifier, member, namespaced, or a dynamic
@@ -1635,8 +1694,7 @@ export namespace Parse {
1635
1694
  * @returns Attribute value (expression, string, or element)
1636
1695
  */
1637
1696
  jsx_parseAttributeValue():
1638
- | ESTreeJSX.JSXExpressionContainer
1639
- | ReturnType<Parser['parseExprAtom']>;
1697
+ ESTreeJSX.JSXExpressionContainer | ReturnType<Parser['parseExprAtom']>;
1640
1698
 
1641
1699
  /**
1642
1700
  * Parse JSX empty expression (for {})
@@ -14,11 +14,7 @@ export type RefValue<T = Element> =
14
14
  | undefined;
15
15
 
16
16
  export type MergeableRef<T> =
17
- | MergeableRefCallback<T>
18
- | MergeableRefObject<T>
19
- | MergeableVueRef<T>
20
- | null
21
- | undefined;
17
+ MergeableRefCallback<T> | MergeableRefObject<T> | MergeableVueRef<T> | null | undefined;
22
18
 
23
19
  export function mergeRefs<T = any>(...refs: Array<MergeableRef<T>>): (node: T | null) => () => void;
24
20
  export function isRefProp(value: unknown): boolean;