@tilua/parser 1.0.1 → 1.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -4498,7 +4498,12 @@ function substitute(t, subst) {
4498
4498
  return t.name && r.kind === "intersection" && !r.name ? { ...r, name: t.name } : r;
4499
4499
  }
4500
4500
  case "genericRef":
4501
- return { kind: "genericRef", name: t.name, typeArguments: t.typeArguments.map((a) => substitute(a, subst)) };
4501
+ return {
4502
+ kind: "genericRef",
4503
+ name: t.name,
4504
+ typeArguments: t.typeArguments.map((a) => substitute(a, subst)),
4505
+ ...t.origin ? { origin: t.origin } : {}
4506
+ };
4502
4507
  case "keyof":
4503
4508
  return { kind: "keyof", target: substitute(t.target, subst) };
4504
4509
  case "templateLiteral":
@@ -4658,6 +4663,7 @@ function optional(t) {
4658
4663
  return union([t, nilType]);
4659
4664
  }
4660
4665
  function widen(t) {
4666
+ if (isAliasNamed(t)) return t;
4661
4667
  switch (t.kind) {
4662
4668
  case "literal":
4663
4669
  return primitive(t.base);
@@ -4697,7 +4703,7 @@ function isAssignable(rawA, rawB) {
4697
4703
  if (expandAlias) {
4698
4704
  if (a.kind === "genericRef" && b.kind !== "genericRef") a = expandAlias(a);
4699
4705
  else if (b.kind === "genericRef" && a.kind !== "genericRef") b = expandAlias(b);
4700
- else if (a.kind === "genericRef" && b.kind === "genericRef" && a.name !== b.name) {
4706
+ else if (a.kind === "genericRef" && b.kind === "genericRef" && !sameRefTarget(a, b)) {
4701
4707
  a = expandAlias(a);
4702
4708
  b = expandAlias(b);
4703
4709
  }
@@ -4807,10 +4813,17 @@ function isAssignableInner(a, b) {
4807
4813
  }
4808
4814
  if (b.kind === "typeParam") return false;
4809
4815
  if (a.kind === "genericRef" || b.kind === "genericRef") {
4810
- return a.kind === "genericRef" && b.kind === "genericRef" && a.name === b.name && a.typeArguments.length === b.typeArguments.length && a.typeArguments.every((x, i) => equalTypes(x, b.typeArguments[i]));
4816
+ return a.kind === "genericRef" && b.kind === "genericRef" && sameRefTarget(a, b) && a.typeArguments.length === b.typeArguments.length && a.typeArguments.every((x, i) => equalTypes(x, b.typeArguments[i]));
4811
4817
  }
4812
4818
  return false;
4813
4819
  }
4820
+ function isAliasNamed(t) {
4821
+ if (t.kind === "object" || t.kind === "intersection") return t.name !== void 0;
4822
+ return t.alias !== void 0;
4823
+ }
4824
+ function sameRefTarget(a, b) {
4825
+ return a.name === b.name && (!a.origin || !b.origin || a.origin === b.origin);
4826
+ }
4814
4827
  function isNoValue(t) {
4815
4828
  return t.kind === "tuple" && t.elements.length === 0;
4816
4829
  }
@@ -5596,6 +5609,9 @@ var TypeAnalyzer = class {
5596
5609
  aliases = new AliasMap();
5597
5610
  /** Uninstantiated alias definitions, for `Name<Args>` instantiation. */
5598
5611
  aliasDefs = /* @__PURE__ */ new Map();
5612
+ /** Put on every ref to one of `aliasDefs`, so a module that imports the
5613
+ * type expands the ref here rather than by its name there. */
5614
+ origin = { expand: (t) => this.expand(t) };
5599
5615
  /** See `resolveClass`. */
5600
5616
  classTypes = /* @__PURE__ */ new WeakMap();
5601
5617
  /** See `instanceType` — one instance type per `class ... end`. */
@@ -6004,7 +6020,8 @@ var TypeAnalyzer = class {
6004
6020
  return {
6005
6021
  kind: "genericRef",
6006
6022
  name: stmt.name.name,
6007
- typeArguments: params.map((p) => typeParam(p.name, p.constraint ? this.resolveType(p.constraint) : void 0))
6023
+ typeArguments: params.map((p) => typeParam(p.name, p.constraint ? this.resolveType(p.constraint) : void 0)),
6024
+ origin: this.origin
6008
6025
  };
6009
6026
  }
6010
6027
  /** The class table: the statics, what it inherits from the class it
@@ -6569,7 +6586,8 @@ var TypeAnalyzer = class {
6569
6586
  return this.expand({
6570
6587
  kind: "genericRef",
6571
6588
  name: node.base,
6572
- typeArguments: node.typeArguments.map((a) => this.resolveType(a))
6589
+ typeArguments: node.typeArguments.map((a) => this.resolveType(a)),
6590
+ origin: this.origin
6573
6591
  });
6574
6592
  }
6575
6593
  const imported = this.importedTypes.get(node.base);
@@ -6582,7 +6600,8 @@ var TypeAnalyzer = class {
6582
6600
  return this.expand({
6583
6601
  kind: "genericRef",
6584
6602
  name,
6585
- typeArguments: node.typeArguments.map((a) => this.resolveType(a))
6603
+ typeArguments: node.typeArguments.map((a) => this.resolveType(a)),
6604
+ origin: this.origin
6586
6605
  });
6587
6606
  }
6588
6607
  return {
@@ -8408,6 +8427,7 @@ var TypeAnalyzer = class {
8408
8427
  * resolving, which is what breaks re-entry on a recursive alias. */
8409
8428
  expand(t) {
8410
8429
  if (t.kind !== "genericRef") return t;
8430
+ if (t.origin && t.origin !== this.origin) return t.origin.expand(t);
8411
8431
  const def = this.aliasDefs.get(t.name);
8412
8432
  if (!def) {
8413
8433
  const imported = this.importedTypes.get(t.name);
package/dist/index.d.cts CHANGED
@@ -1223,6 +1223,15 @@ interface GenericRefType {
1223
1223
  kind: "genericRef";
1224
1224
  name: string;
1225
1225
  typeArguments: Type[];
1226
+ /** The module whose alias this names. A recursive alias is left as a ref
1227
+ * inside its own structure, and that ref travels with the type into every
1228
+ * module that imports it — where `name` may mean nothing, or a different
1229
+ * type. Expanding through `origin` reads the name where it was written. */
1230
+ origin?: TypeOrigin;
1231
+ }
1232
+ /** A module's own alias resolution, handed out on the refs it creates. */
1233
+ interface TypeOrigin {
1234
+ expand(t: GenericRefType): Type;
1226
1235
  }
1227
1236
  /** `keyof T`. */
1228
1237
  interface KeyofType {
@@ -1679,4 +1688,4 @@ declare const tilua: {
1679
1688
  readonly analyzeTypes: typeof analyzeTypes;
1680
1689
  };
1681
1690
 
1682
- export { type AnalyzeTypesOptions, type AnyType, type ArrayExpression, type ArrayPattern, type ArrayPatternElement, type ArrayType, type ArrayTypeNode, type AsConstExpression, type AssignmentStatement, type BaseNode, type BaseToken, type BinaryExpression, BinaryOperators, type Binding, type BindingId, type BindingKind, type BindingTarget, type Block, type BooleanLiteral, type BreakStatement, type BuildTarget, CONFIG_FILE_NAMES, type CallExpression, type CallStatement, type ClassAccessor, type ClassConstructor, type ClassDeclaration, type ClassExpression, type ClassField, type ClassInfo, type ClassLike, type ClassMember, type ClassMethod, type CompoundAssignmentStatement, type ConditionalType, type ConditionalTypeNode, type ConfigLookup, type ConfigProblem, type ContinueStatement, type DeclareClassStatement, type DeclareStatement, type DifferenceType, type DifferenceTypeNode, type Directive, type DirectiveKind, type DirectiveOutcome, type Directives, type DoStatement, type EOFToken, type ErrorExpression, type ErrorStatement, type ExportAllStatement, type ExportDefaultStatement, type ExportNamedStatement, type ExportSpecifier, type ExportStatement, type ExportTypeAliasStatement, type ExportedType, type Expression, type ExpressionStatement, type FunctionBody, type FunctionDeclaration, type FunctionDeclarationStatement, type FunctionExpression, type FunctionName, type FunctionParam, type FunctionParameter, type FunctionSignature, type FunctionType, type FunctionTypeNode, type FunctionTypeParameter, type GenericForStatement, type GenericRefType, type GenericTypeParameter, type Identifier, type IdentifierPattern, type IdentifierToken, type IfClause, type IfElseExpression, type IfStatement, type ImportSpecifier, type ImportStatement, type IndexExpression, type IndexedAccessType, type IndexedAccessTypeNode, type InferType, type InferTypeNode, type InterpolatedStringExpression, type InterpolatedStringPart, type InterpolatedStringPart_Expression, type InterpolatedStringPart_String, type InterpolatedStringToken, type IntersectionType, type IntersectionTypeNode, type KeyofType, type KeyofTypeNode, type KeywordToken, Keywords, LexError, type LiteralToken, type LiteralType, type LoweringModule, type LoweringPlugin, type MappedType, type MappedTypeNode, type MemberExpression, type MethodCall, type MethodCallExpression, type MethodLowering, type ModuleExports, type NeverType, type NewExpression, type NilLiteral, type Node, type NumberLiteral, type NumericForStatement, type ObjectPattern, type ObjectPatternProperty, type ObjectProperty, type ObjectType, type OperatorToken, Operators, PRELUDE_SOURCE, type ParenthesizedExpression, type ParenthesizedTypeNode, ParseError, type ParserOptions, type PrimitiveName, type PrimitiveType, type Program, type ProjectHost, type PunctuatorToken, Punctuators, type RecoverResult, type RepeatStatement, type ReturnStatement, type SatisfiesExpression, type ScopeAnalysis, type ScopeDiagnostic, type SourceComment, type SourceMapNode, type SourceMapOptions, type SourceMapTypes, type SpreadElement, type Statement, type StringLiteral, type SuperExpression, type TableExpression, type TableField, type TableTypeNode, type TableTypeProperty, type TemplateLiteralType, type TemplateLiteralTypeNode, type TiluaConfig, type Token, type TokenizeOptions, type TupleType, type TupleTypeNode, type Type, type TypeAliasStatement, type TypeAnalysis, type TypeAssertionExpression, type TypeDiagnostic, type TypeLibraries, type TypeLiteralBoolean, type TypeLiteralNumber, type TypeLiteralString, type TypeNode, type TypePackNode, type TypeParamType, type TypePredicate, type TypePredicateNode, type TypeReference, type TypedIdentifier, type TypeofTypeNode, UNUSED_EXPECT_ERROR, type UnaryExpression, UnaryOperators, type UnionType, type UnionTypeNode, type UnknownType, type VarargExpression, type VariableDeclaration, type VariadicTypeNode, type WhileStatement, aliasNameOf, analyzeScopes, analyzeTypes, anyType, applyDirectives, arrayOf, booleanType, bufferType, containsTypeParam, declaredUnknownType, tilua as default, difference, directivesOf, equalTypes, falsyType, findConfig, fn, formatType, getBinding, intersection, isAssignable, isClassType, isGlobal, isPossiblyFalsy, isPossiblyTruthy, isUnassignedGlobal, literal, loadConfig, matchInfer, moduleCandidates, moduleExports, narrowExclude, narrowFalsy, narrowTo, narrowTruthy, neverType, nilType, nodeHost, numberType, objectType, optional, overlaps, parse, parseExpressionFromSource, parseTokens, parseWithRecovery, primitive, readDirectives, resolveModulePath, resolveTypeLibraries, setAliasExpander, setDeferredBound, sourceMapTypes, stringType, stripJsonComments, substitute, templateMatches, threadType, tilua, tokenize, tuple, typeParam, unify, union, unknownType, widen, withAliasName, withoutAliasName };
1691
+ export { type AnalyzeTypesOptions, type AnyType, type ArrayExpression, type ArrayPattern, type ArrayPatternElement, type ArrayType, type ArrayTypeNode, type AsConstExpression, type AssignmentStatement, type BaseNode, type BaseToken, type BinaryExpression, BinaryOperators, type Binding, type BindingId, type BindingKind, type BindingTarget, type Block, type BooleanLiteral, type BreakStatement, type BuildTarget, CONFIG_FILE_NAMES, type CallExpression, type CallStatement, type ClassAccessor, type ClassConstructor, type ClassDeclaration, type ClassExpression, type ClassField, type ClassInfo, type ClassLike, type ClassMember, type ClassMethod, type CompoundAssignmentStatement, type ConditionalType, type ConditionalTypeNode, type ConfigLookup, type ConfigProblem, type ContinueStatement, type DeclareClassStatement, type DeclareStatement, type DifferenceType, type DifferenceTypeNode, type Directive, type DirectiveKind, type DirectiveOutcome, type Directives, type DoStatement, type EOFToken, type ErrorExpression, type ErrorStatement, type ExportAllStatement, type ExportDefaultStatement, type ExportNamedStatement, type ExportSpecifier, type ExportStatement, type ExportTypeAliasStatement, type ExportedType, type Expression, type ExpressionStatement, type FunctionBody, type FunctionDeclaration, type FunctionDeclarationStatement, type FunctionExpression, type FunctionName, type FunctionParam, type FunctionParameter, type FunctionSignature, type FunctionType, type FunctionTypeNode, type FunctionTypeParameter, type GenericForStatement, type GenericRefType, type GenericTypeParameter, type Identifier, type IdentifierPattern, type IdentifierToken, type IfClause, type IfElseExpression, type IfStatement, type ImportSpecifier, type ImportStatement, type IndexExpression, type IndexedAccessType, type IndexedAccessTypeNode, type InferType, type InferTypeNode, type InterpolatedStringExpression, type InterpolatedStringPart, type InterpolatedStringPart_Expression, type InterpolatedStringPart_String, type InterpolatedStringToken, type IntersectionType, type IntersectionTypeNode, type KeyofType, type KeyofTypeNode, type KeywordToken, Keywords, LexError, type LiteralToken, type LiteralType, type LoweringModule, type LoweringPlugin, type MappedType, type MappedTypeNode, type MemberExpression, type MethodCall, type MethodCallExpression, type MethodLowering, type ModuleExports, type NeverType, type NewExpression, type NilLiteral, type Node, type NumberLiteral, type NumericForStatement, type ObjectPattern, type ObjectPatternProperty, type ObjectProperty, type ObjectType, type OperatorToken, Operators, PRELUDE_SOURCE, type ParenthesizedExpression, type ParenthesizedTypeNode, ParseError, type ParserOptions, type PrimitiveName, type PrimitiveType, type Program, type ProjectHost, type PunctuatorToken, Punctuators, type RecoverResult, type RepeatStatement, type ReturnStatement, type SatisfiesExpression, type ScopeAnalysis, type ScopeDiagnostic, type SourceComment, type SourceMapNode, type SourceMapOptions, type SourceMapTypes, type SpreadElement, type Statement, type StringLiteral, type SuperExpression, type TableExpression, type TableField, type TableTypeNode, type TableTypeProperty, type TemplateLiteralType, type TemplateLiteralTypeNode, type TiluaConfig, type Token, type TokenizeOptions, type TupleType, type TupleTypeNode, type Type, type TypeAliasStatement, type TypeAnalysis, type TypeAssertionExpression, type TypeDiagnostic, type TypeLibraries, type TypeLiteralBoolean, type TypeLiteralNumber, type TypeLiteralString, type TypeNode, type TypeOrigin, type TypePackNode, type TypeParamType, type TypePredicate, type TypePredicateNode, type TypeReference, type TypedIdentifier, type TypeofTypeNode, UNUSED_EXPECT_ERROR, type UnaryExpression, UnaryOperators, type UnionType, type UnionTypeNode, type UnknownType, type VarargExpression, type VariableDeclaration, type VariadicTypeNode, type WhileStatement, aliasNameOf, analyzeScopes, analyzeTypes, anyType, applyDirectives, arrayOf, booleanType, bufferType, containsTypeParam, declaredUnknownType, tilua as default, difference, directivesOf, equalTypes, falsyType, findConfig, fn, formatType, getBinding, intersection, isAssignable, isClassType, isGlobal, isPossiblyFalsy, isPossiblyTruthy, isUnassignedGlobal, literal, loadConfig, matchInfer, moduleCandidates, moduleExports, narrowExclude, narrowFalsy, narrowTo, narrowTruthy, neverType, nilType, nodeHost, numberType, objectType, optional, overlaps, parse, parseExpressionFromSource, parseTokens, parseWithRecovery, primitive, readDirectives, resolveModulePath, resolveTypeLibraries, setAliasExpander, setDeferredBound, sourceMapTypes, stringType, stripJsonComments, substitute, templateMatches, threadType, tilua, tokenize, tuple, typeParam, unify, union, unknownType, widen, withAliasName, withoutAliasName };
package/dist/index.d.ts CHANGED
@@ -1223,6 +1223,15 @@ interface GenericRefType {
1223
1223
  kind: "genericRef";
1224
1224
  name: string;
1225
1225
  typeArguments: Type[];
1226
+ /** The module whose alias this names. A recursive alias is left as a ref
1227
+ * inside its own structure, and that ref travels with the type into every
1228
+ * module that imports it — where `name` may mean nothing, or a different
1229
+ * type. Expanding through `origin` reads the name where it was written. */
1230
+ origin?: TypeOrigin;
1231
+ }
1232
+ /** A module's own alias resolution, handed out on the refs it creates. */
1233
+ interface TypeOrigin {
1234
+ expand(t: GenericRefType): Type;
1226
1235
  }
1227
1236
  /** `keyof T`. */
1228
1237
  interface KeyofType {
@@ -1679,4 +1688,4 @@ declare const tilua: {
1679
1688
  readonly analyzeTypes: typeof analyzeTypes;
1680
1689
  };
1681
1690
 
1682
- export { type AnalyzeTypesOptions, type AnyType, type ArrayExpression, type ArrayPattern, type ArrayPatternElement, type ArrayType, type ArrayTypeNode, type AsConstExpression, type AssignmentStatement, type BaseNode, type BaseToken, type BinaryExpression, BinaryOperators, type Binding, type BindingId, type BindingKind, type BindingTarget, type Block, type BooleanLiteral, type BreakStatement, type BuildTarget, CONFIG_FILE_NAMES, type CallExpression, type CallStatement, type ClassAccessor, type ClassConstructor, type ClassDeclaration, type ClassExpression, type ClassField, type ClassInfo, type ClassLike, type ClassMember, type ClassMethod, type CompoundAssignmentStatement, type ConditionalType, type ConditionalTypeNode, type ConfigLookup, type ConfigProblem, type ContinueStatement, type DeclareClassStatement, type DeclareStatement, type DifferenceType, type DifferenceTypeNode, type Directive, type DirectiveKind, type DirectiveOutcome, type Directives, type DoStatement, type EOFToken, type ErrorExpression, type ErrorStatement, type ExportAllStatement, type ExportDefaultStatement, type ExportNamedStatement, type ExportSpecifier, type ExportStatement, type ExportTypeAliasStatement, type ExportedType, type Expression, type ExpressionStatement, type FunctionBody, type FunctionDeclaration, type FunctionDeclarationStatement, type FunctionExpression, type FunctionName, type FunctionParam, type FunctionParameter, type FunctionSignature, type FunctionType, type FunctionTypeNode, type FunctionTypeParameter, type GenericForStatement, type GenericRefType, type GenericTypeParameter, type Identifier, type IdentifierPattern, type IdentifierToken, type IfClause, type IfElseExpression, type IfStatement, type ImportSpecifier, type ImportStatement, type IndexExpression, type IndexedAccessType, type IndexedAccessTypeNode, type InferType, type InferTypeNode, type InterpolatedStringExpression, type InterpolatedStringPart, type InterpolatedStringPart_Expression, type InterpolatedStringPart_String, type InterpolatedStringToken, type IntersectionType, type IntersectionTypeNode, type KeyofType, type KeyofTypeNode, type KeywordToken, Keywords, LexError, type LiteralToken, type LiteralType, type LoweringModule, type LoweringPlugin, type MappedType, type MappedTypeNode, type MemberExpression, type MethodCall, type MethodCallExpression, type MethodLowering, type ModuleExports, type NeverType, type NewExpression, type NilLiteral, type Node, type NumberLiteral, type NumericForStatement, type ObjectPattern, type ObjectPatternProperty, type ObjectProperty, type ObjectType, type OperatorToken, Operators, PRELUDE_SOURCE, type ParenthesizedExpression, type ParenthesizedTypeNode, ParseError, type ParserOptions, type PrimitiveName, type PrimitiveType, type Program, type ProjectHost, type PunctuatorToken, Punctuators, type RecoverResult, type RepeatStatement, type ReturnStatement, type SatisfiesExpression, type ScopeAnalysis, type ScopeDiagnostic, type SourceComment, type SourceMapNode, type SourceMapOptions, type SourceMapTypes, type SpreadElement, type Statement, type StringLiteral, type SuperExpression, type TableExpression, type TableField, type TableTypeNode, type TableTypeProperty, type TemplateLiteralType, type TemplateLiteralTypeNode, type TiluaConfig, type Token, type TokenizeOptions, type TupleType, type TupleTypeNode, type Type, type TypeAliasStatement, type TypeAnalysis, type TypeAssertionExpression, type TypeDiagnostic, type TypeLibraries, type TypeLiteralBoolean, type TypeLiteralNumber, type TypeLiteralString, type TypeNode, type TypePackNode, type TypeParamType, type TypePredicate, type TypePredicateNode, type TypeReference, type TypedIdentifier, type TypeofTypeNode, UNUSED_EXPECT_ERROR, type UnaryExpression, UnaryOperators, type UnionType, type UnionTypeNode, type UnknownType, type VarargExpression, type VariableDeclaration, type VariadicTypeNode, type WhileStatement, aliasNameOf, analyzeScopes, analyzeTypes, anyType, applyDirectives, arrayOf, booleanType, bufferType, containsTypeParam, declaredUnknownType, tilua as default, difference, directivesOf, equalTypes, falsyType, findConfig, fn, formatType, getBinding, intersection, isAssignable, isClassType, isGlobal, isPossiblyFalsy, isPossiblyTruthy, isUnassignedGlobal, literal, loadConfig, matchInfer, moduleCandidates, moduleExports, narrowExclude, narrowFalsy, narrowTo, narrowTruthy, neverType, nilType, nodeHost, numberType, objectType, optional, overlaps, parse, parseExpressionFromSource, parseTokens, parseWithRecovery, primitive, readDirectives, resolveModulePath, resolveTypeLibraries, setAliasExpander, setDeferredBound, sourceMapTypes, stringType, stripJsonComments, substitute, templateMatches, threadType, tilua, tokenize, tuple, typeParam, unify, union, unknownType, widen, withAliasName, withoutAliasName };
1691
+ export { type AnalyzeTypesOptions, type AnyType, type ArrayExpression, type ArrayPattern, type ArrayPatternElement, type ArrayType, type ArrayTypeNode, type AsConstExpression, type AssignmentStatement, type BaseNode, type BaseToken, type BinaryExpression, BinaryOperators, type Binding, type BindingId, type BindingKind, type BindingTarget, type Block, type BooleanLiteral, type BreakStatement, type BuildTarget, CONFIG_FILE_NAMES, type CallExpression, type CallStatement, type ClassAccessor, type ClassConstructor, type ClassDeclaration, type ClassExpression, type ClassField, type ClassInfo, type ClassLike, type ClassMember, type ClassMethod, type CompoundAssignmentStatement, type ConditionalType, type ConditionalTypeNode, type ConfigLookup, type ConfigProblem, type ContinueStatement, type DeclareClassStatement, type DeclareStatement, type DifferenceType, type DifferenceTypeNode, type Directive, type DirectiveKind, type DirectiveOutcome, type Directives, type DoStatement, type EOFToken, type ErrorExpression, type ErrorStatement, type ExportAllStatement, type ExportDefaultStatement, type ExportNamedStatement, type ExportSpecifier, type ExportStatement, type ExportTypeAliasStatement, type ExportedType, type Expression, type ExpressionStatement, type FunctionBody, type FunctionDeclaration, type FunctionDeclarationStatement, type FunctionExpression, type FunctionName, type FunctionParam, type FunctionParameter, type FunctionSignature, type FunctionType, type FunctionTypeNode, type FunctionTypeParameter, type GenericForStatement, type GenericRefType, type GenericTypeParameter, type Identifier, type IdentifierPattern, type IdentifierToken, type IfClause, type IfElseExpression, type IfStatement, type ImportSpecifier, type ImportStatement, type IndexExpression, type IndexedAccessType, type IndexedAccessTypeNode, type InferType, type InferTypeNode, type InterpolatedStringExpression, type InterpolatedStringPart, type InterpolatedStringPart_Expression, type InterpolatedStringPart_String, type InterpolatedStringToken, type IntersectionType, type IntersectionTypeNode, type KeyofType, type KeyofTypeNode, type KeywordToken, Keywords, LexError, type LiteralToken, type LiteralType, type LoweringModule, type LoweringPlugin, type MappedType, type MappedTypeNode, type MemberExpression, type MethodCall, type MethodCallExpression, type MethodLowering, type ModuleExports, type NeverType, type NewExpression, type NilLiteral, type Node, type NumberLiteral, type NumericForStatement, type ObjectPattern, type ObjectPatternProperty, type ObjectProperty, type ObjectType, type OperatorToken, Operators, PRELUDE_SOURCE, type ParenthesizedExpression, type ParenthesizedTypeNode, ParseError, type ParserOptions, type PrimitiveName, type PrimitiveType, type Program, type ProjectHost, type PunctuatorToken, Punctuators, type RecoverResult, type RepeatStatement, type ReturnStatement, type SatisfiesExpression, type ScopeAnalysis, type ScopeDiagnostic, type SourceComment, type SourceMapNode, type SourceMapOptions, type SourceMapTypes, type SpreadElement, type Statement, type StringLiteral, type SuperExpression, type TableExpression, type TableField, type TableTypeNode, type TableTypeProperty, type TemplateLiteralType, type TemplateLiteralTypeNode, type TiluaConfig, type Token, type TokenizeOptions, type TupleType, type TupleTypeNode, type Type, type TypeAliasStatement, type TypeAnalysis, type TypeAssertionExpression, type TypeDiagnostic, type TypeLibraries, type TypeLiteralBoolean, type TypeLiteralNumber, type TypeLiteralString, type TypeNode, type TypeOrigin, type TypePackNode, type TypeParamType, type TypePredicate, type TypePredicateNode, type TypeReference, type TypedIdentifier, type TypeofTypeNode, UNUSED_EXPECT_ERROR, type UnaryExpression, UnaryOperators, type UnionType, type UnionTypeNode, type UnknownType, type VarargExpression, type VariableDeclaration, type VariadicTypeNode, type WhileStatement, aliasNameOf, analyzeScopes, analyzeTypes, anyType, applyDirectives, arrayOf, booleanType, bufferType, containsTypeParam, declaredUnknownType, tilua as default, difference, directivesOf, equalTypes, falsyType, findConfig, fn, formatType, getBinding, intersection, isAssignable, isClassType, isGlobal, isPossiblyFalsy, isPossiblyTruthy, isUnassignedGlobal, literal, loadConfig, matchInfer, moduleCandidates, moduleExports, narrowExclude, narrowFalsy, narrowTo, narrowTruthy, neverType, nilType, nodeHost, numberType, objectType, optional, overlaps, parse, parseExpressionFromSource, parseTokens, parseWithRecovery, primitive, readDirectives, resolveModulePath, resolveTypeLibraries, setAliasExpander, setDeferredBound, sourceMapTypes, stringType, stripJsonComments, substitute, templateMatches, threadType, tilua, tokenize, tuple, typeParam, unify, union, unknownType, widen, withAliasName, withoutAliasName };
package/dist/index.js CHANGED
@@ -4395,7 +4395,12 @@ function substitute(t, subst) {
4395
4395
  return t.name && r.kind === "intersection" && !r.name ? { ...r, name: t.name } : r;
4396
4396
  }
4397
4397
  case "genericRef":
4398
- return { kind: "genericRef", name: t.name, typeArguments: t.typeArguments.map((a) => substitute(a, subst)) };
4398
+ return {
4399
+ kind: "genericRef",
4400
+ name: t.name,
4401
+ typeArguments: t.typeArguments.map((a) => substitute(a, subst)),
4402
+ ...t.origin ? { origin: t.origin } : {}
4403
+ };
4399
4404
  case "keyof":
4400
4405
  return { kind: "keyof", target: substitute(t.target, subst) };
4401
4406
  case "templateLiteral":
@@ -4555,6 +4560,7 @@ function optional(t) {
4555
4560
  return union([t, nilType]);
4556
4561
  }
4557
4562
  function widen(t) {
4563
+ if (isAliasNamed(t)) return t;
4558
4564
  switch (t.kind) {
4559
4565
  case "literal":
4560
4566
  return primitive(t.base);
@@ -4594,7 +4600,7 @@ function isAssignable(rawA, rawB) {
4594
4600
  if (expandAlias) {
4595
4601
  if (a.kind === "genericRef" && b.kind !== "genericRef") a = expandAlias(a);
4596
4602
  else if (b.kind === "genericRef" && a.kind !== "genericRef") b = expandAlias(b);
4597
- else if (a.kind === "genericRef" && b.kind === "genericRef" && a.name !== b.name) {
4603
+ else if (a.kind === "genericRef" && b.kind === "genericRef" && !sameRefTarget(a, b)) {
4598
4604
  a = expandAlias(a);
4599
4605
  b = expandAlias(b);
4600
4606
  }
@@ -4704,10 +4710,17 @@ function isAssignableInner(a, b) {
4704
4710
  }
4705
4711
  if (b.kind === "typeParam") return false;
4706
4712
  if (a.kind === "genericRef" || b.kind === "genericRef") {
4707
- return a.kind === "genericRef" && b.kind === "genericRef" && a.name === b.name && a.typeArguments.length === b.typeArguments.length && a.typeArguments.every((x, i) => equalTypes(x, b.typeArguments[i]));
4713
+ return a.kind === "genericRef" && b.kind === "genericRef" && sameRefTarget(a, b) && a.typeArguments.length === b.typeArguments.length && a.typeArguments.every((x, i) => equalTypes(x, b.typeArguments[i]));
4708
4714
  }
4709
4715
  return false;
4710
4716
  }
4717
+ function isAliasNamed(t) {
4718
+ if (t.kind === "object" || t.kind === "intersection") return t.name !== void 0;
4719
+ return t.alias !== void 0;
4720
+ }
4721
+ function sameRefTarget(a, b) {
4722
+ return a.name === b.name && (!a.origin || !b.origin || a.origin === b.origin);
4723
+ }
4711
4724
  function isNoValue(t) {
4712
4725
  return t.kind === "tuple" && t.elements.length === 0;
4713
4726
  }
@@ -5493,6 +5506,9 @@ var TypeAnalyzer = class {
5493
5506
  aliases = new AliasMap();
5494
5507
  /** Uninstantiated alias definitions, for `Name<Args>` instantiation. */
5495
5508
  aliasDefs = /* @__PURE__ */ new Map();
5509
+ /** Put on every ref to one of `aliasDefs`, so a module that imports the
5510
+ * type expands the ref here rather than by its name there. */
5511
+ origin = { expand: (t) => this.expand(t) };
5496
5512
  /** See `resolveClass`. */
5497
5513
  classTypes = /* @__PURE__ */ new WeakMap();
5498
5514
  /** See `instanceType` — one instance type per `class ... end`. */
@@ -5901,7 +5917,8 @@ var TypeAnalyzer = class {
5901
5917
  return {
5902
5918
  kind: "genericRef",
5903
5919
  name: stmt.name.name,
5904
- typeArguments: params.map((p) => typeParam(p.name, p.constraint ? this.resolveType(p.constraint) : void 0))
5920
+ typeArguments: params.map((p) => typeParam(p.name, p.constraint ? this.resolveType(p.constraint) : void 0)),
5921
+ origin: this.origin
5905
5922
  };
5906
5923
  }
5907
5924
  /** The class table: the statics, what it inherits from the class it
@@ -6466,7 +6483,8 @@ var TypeAnalyzer = class {
6466
6483
  return this.expand({
6467
6484
  kind: "genericRef",
6468
6485
  name: node.base,
6469
- typeArguments: node.typeArguments.map((a) => this.resolveType(a))
6486
+ typeArguments: node.typeArguments.map((a) => this.resolveType(a)),
6487
+ origin: this.origin
6470
6488
  });
6471
6489
  }
6472
6490
  const imported = this.importedTypes.get(node.base);
@@ -6479,7 +6497,8 @@ var TypeAnalyzer = class {
6479
6497
  return this.expand({
6480
6498
  kind: "genericRef",
6481
6499
  name,
6482
- typeArguments: node.typeArguments.map((a) => this.resolveType(a))
6500
+ typeArguments: node.typeArguments.map((a) => this.resolveType(a)),
6501
+ origin: this.origin
6483
6502
  });
6484
6503
  }
6485
6504
  return {
@@ -8305,6 +8324,7 @@ var TypeAnalyzer = class {
8305
8324
  * resolving, which is what breaks re-entry on a recursive alias. */
8306
8325
  expand(t) {
8307
8326
  if (t.kind !== "genericRef") return t;
8327
+ if (t.origin && t.origin !== this.origin) return t.origin.expand(t);
8308
8328
  const def = this.aliasDefs.get(t.name);
8309
8329
  if (!def) {
8310
8330
  const imported = this.importedTypes.get(t.name);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tilua/parser",
3
- "version": "1.0.1",
3
+ "version": "1.0.2",
4
4
  "description": "tilua parser for roblox",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.js",