Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork2.8k
feat(ast-spec): tighter types and documentation for declaration/*#9211
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Changes fromall commits
4407bad391172f1ffdb1653aa2747feb47919374ea091cc9efc730f1File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -12,24 +12,23 @@ export interface ExportAllDeclaration extends BaseNode { | ||
| * ``` | ||
| * export * from 'mod' assert { type: 'json' }; | ||
| * ``` | ||
| * @deprecated Replaced with {@link `attributes`}. | ||
| */ | ||
| assertions: ImportAttribute[]; | ||
| /** | ||
| * The attributes declared for the export. | ||
| * ``` | ||
| * export * from 'mod'with { type: 'json' }; | ||
| * ``` | ||
| */ | ||
| attributes: ImportAttribute[]; | ||
| /** | ||
| * The name for the exported items (`as X`). `null` if no name is assigned. | ||
| */ | ||
| exported: Identifier | null; | ||
| /** | ||
| * The kind of the export. | ||
| */ | ||
MemberAuthor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. TS now allows | ||
| exportKind: ExportKind; | ||
| /** | ||
| * The source module being exported from. | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,6 @@ | ||
| import type { AST_NODE_TYPES } from '../../ast-node-types'; | ||
| import type { BaseNode } from '../../base/BaseNode'; | ||
| import type { DefaultExportDeclarations } from '../../unions/ExportDeclaration'; | ||
| export interface ExportDefaultDeclaration extends BaseNode { | ||
| type: AST_NODE_TYPES.ExportDefaultDeclaration; | ||
| @@ -10,7 +9,7 @@ export interface ExportDefaultDeclaration extends BaseNode { | ||
| */ | ||
| declaration: DefaultExportDeclarations; | ||
| /** | ||
| * The kind of the export. Always `value` for default exports. | ||
| */ | ||
| exportKind:'value'; | ||
MemberAuthor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. Tightened: | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -20,7 +20,7 @@ interface ExportNamedDeclarationBase extends BaseNode { | ||
| /** | ||
| * The attributes declared for the export. | ||
| * ``` | ||
| * export { foo } from 'mod'with { type: 'json' }; | ||
| * ``` | ||
| * This will be an empty array if `source` is `null` | ||
| */ | ||
| @@ -51,6 +51,13 @@ interface ExportNamedDeclarationBase extends BaseNode { | ||
| specifiers: ExportSpecifier[]; | ||
| } | ||
| /** | ||
| * Exporting names from the current module. | ||
| * ``` | ||
| * export {}; | ||
| * export { a, b }; | ||
| * ``` | ||
| */ | ||
| export interface ExportNamedDeclarationWithoutSourceWithMultiple | ||
| extends ExportNamedDeclarationBase { | ||
| /** | ||
| @@ -64,9 +71,14 @@ export interface ExportNamedDeclarationWithoutSourceWithMultiple | ||
| attributes: ImportAttribute[]; | ||
| declaration: null; | ||
| source: null; | ||
MemberAuthor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. Removals here are not breaking because these properties are already declared on the base | ||
| } | ||
| /** | ||
| * Exporting a single named declaration. | ||
| * ``` | ||
| * export const x = 1; | ||
| * ``` | ||
| */ | ||
| export interface ExportNamedDeclarationWithoutSourceWithSingle | ||
| extends ExportNamedDeclarationBase { | ||
| /** | ||
| @@ -80,24 +92,22 @@ export interface ExportNamedDeclarationWithoutSourceWithSingle | ||
| attributes: ImportAttribute[]; | ||
| declaration: NamedExportDeclarations; | ||
| source: null; | ||
| /** | ||
| * This will always be an empty array. | ||
| */ | ||
| specifiers: ExportSpecifier[]; | ||
| } | ||
| /** | ||
| * Export names from another module. | ||
| * ``` | ||
| * export { a, b } from 'mod'; | ||
| * ``` | ||
| */ | ||
| export interface ExportNamedDeclarationWithSource | ||
| extends ExportNamedDeclarationBase { | ||
| declaration: null; | ||
| source: StringLiteral; | ||
| } | ||
| export type ExportNamedDeclaration = | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -2,13 +2,13 @@ import type { AST_NODE_TYPES } from '../../ast-node-types'; | ||
| import type { BaseNode } from '../../base/BaseNode'; | ||
| import type { Identifier } from '../../expression/Identifier/spec'; | ||
| import type { TSExternalModuleReference } from '../../special/TSExternalModuleReference/spec'; | ||
| import type {TSQualifiedName } from '../../type/TSQualifiedName/spec'; | ||
| import type { ImportKind } from '../ExportAndImportKind'; | ||
| interfaceTSImportEqualsDeclarationBase extends BaseNode { | ||
| type: AST_NODE_TYPES.TSImportEqualsDeclaration; | ||
| /** | ||
| * The locally imported name. | ||
| */ | ||
| id: Identifier; | ||
| /** | ||
| @@ -19,7 +19,45 @@ export interface TSImportEqualsDeclaration extends BaseNode { | ||
| * import F3 = require('mod'); | ||
| * ``` | ||
| */ | ||
| moduleReference: Identifier | TSExternalModuleReference | TSQualifiedName; | ||
| /** | ||
| * The kind of the import. Always `'value'` unless `moduleReference` is a | ||
| * `TSExternalModuleReference`. | ||
| */ | ||
| importKind: ImportKind; | ||
| } | ||
| export interface TSImportEqualsNamespaceDeclaration | ||
| extends TSImportEqualsDeclarationBase { | ||
| /** | ||
| * The value being aliased. | ||
| * ``` | ||
| * import F1 = A; | ||
| * import F2 = A.B.C; | ||
| * ``` | ||
| */ | ||
| moduleReference: Identifier | TSQualifiedName; | ||
| /** | ||
| * The kind of the import. | ||
| */ | ||
| importKind: 'value'; | ||
| } | ||
| export interface TSImportEqualsRequireDeclaration | ||
| extends TSImportEqualsDeclarationBase { | ||
| /** | ||
| * The value being aliased. | ||
| * ``` | ||
| * import F3 = require('mod'); | ||
| * ``` | ||
| */ | ||
| moduleReference: TSExternalModuleReference; | ||
| /** | ||
| * The kind of the import. | ||
| */ | ||
| importKind: ImportKind; | ||
| } | ||
| export type TSImportEqualsDeclaration = | ||
| | TSImportEqualsNamespaceDeclaration | ||
| | TSImportEqualsRequireDeclaration; | ||
Comment on lines +61 to +63 MemberAuthor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. Changed to union | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -22,14 +22,12 @@ interface TSModuleDeclarationBase extends BaseNode { | ||
| /** | ||
| * The body of the module. | ||
| * This can only be `undefined` for the code `declare module 'mod';` | ||
| */ | ||
| body?: TSModuleBlock; | ||
| /** | ||
| * Whether this is a global declaration | ||
| * | ||
| * @deprecated Use {@link kind} instead | ||
| */ | ||
| // TODO - remove this in the next major (we have `.kind` now) | ||
| global: boolean; | ||
| @@ -50,64 +48,81 @@ interface TSModuleDeclarationBase extends BaseNode { | ||
| * module 'foo' {} | ||
| * ^^^^^^ | ||
| * | ||
| * global {} | ||
| * ^^^^^^ | ||
| * ``` | ||
| */ | ||
| kind: TSModuleDeclarationKind; | ||
| } | ||
| export interface TSModuleDeclarationNamespace extends TSModuleDeclarationBase { | ||
| kind: 'namespace'; | ||
| id: Identifier | TSQualifiedName; | ||
| body: TSModuleBlock; | ||
| } | ||
| export interface TSModuleDeclarationGlobal extends TSModuleDeclarationBase { | ||
| kind: 'global'; | ||
| /** | ||
| * This will always be an Identifier with name `global` | ||
| */ | ||
| id: Identifier; | ||
| body: TSModuleBlock; | ||
| } | ||
| interface TSModuleDeclarationModuleBase extends TSModuleDeclarationBase { | ||
| kind: 'module'; | ||
| } | ||
| /** | ||
| * A string module declaration that is not declared: | ||
| * ``` | ||
| * module 'foo' {} | ||
| * ``` | ||
| */ | ||
| export interface TSModuleDeclarationModuleWithStringIdNotDeclared | ||
| extends TSModuleDeclarationModuleBase { | ||
| kind: 'module'; | ||
| id: StringLiteral; | ||
| declare: false; | ||
| body: TSModuleBlock; | ||
| } | ||
| /** | ||
| * A string module declaration that is declared: | ||
| * ``` | ||
| * declare module 'foo' {} | ||
| * declare module 'foo'; | ||
| * ``` | ||
| */ | ||
| export interface TSModuleDeclarationModuleWithStringIdDeclared | ||
| extends TSModuleDeclarationModuleBase { | ||
| kind: 'module'; | ||
| id: StringLiteral; | ||
| declare: true; | ||
| body?: TSModuleBlock; | ||
| } | ||
| /** | ||
| * The legacy module declaration, replaced with namespace declarations. | ||
| * ``` | ||
| * module A {} | ||
| * ``` | ||
| */ | ||
| export interface TSModuleDeclarationModuleWithIdentifierId | ||
| extends TSModuleDeclarationModuleBase { | ||
| kind: 'module'; | ||
| id: Identifier; | ||
| // TODO: we emit the wrong AST for `module A.B {}` | ||
| // https://github.com/typescript-eslint/typescript-eslint/pull/6272 only fixed namespaces | ||
| // Maybe not worth fixing since it's legacy | ||
Comment on lines +114 to +116 MemberAuthor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. Worth pointing out | ||
| body: TSModuleBlock; | ||
| } | ||
| export type TSModuleDeclarationModuleWithStringId = | ||
| | TSModuleDeclarationModuleWithStringIdDeclared | ||
| | TSModuleDeclarationModuleWithStringIdNotDeclared; | ||
| export type TSModuleDeclarationModule = | ||
| | TSModuleDeclarationModuleWithIdentifierId | ||
| | TSModuleDeclarationModuleWithStringId; | ||
| export type TSModuleDeclaration = | ||
| | TSModuleDeclarationGlobal | ||
| | TSModuleDeclarationModule | ||
Uh oh!
There was an error while loading.Please reload this page.