| 1 | "use strict";Object.defineProperty(exports, "__esModule", {value: true});var _tokenizer = require('../parser/tokenizer');
|
|---|
| 2 | var _types = require('../parser/tokenizer/types');
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 | const EMPTY_DECLARATION_INFO = {
|
|---|
| 11 | typeDeclarations: new Set(),
|
|---|
| 12 | valueDeclarations: new Set(),
|
|---|
| 13 | }; exports.EMPTY_DECLARATION_INFO = EMPTY_DECLARATION_INFO;
|
|---|
| 14 |
|
|---|
| 15 | /**
|
|---|
| 16 | * Get all top-level identifiers that should be preserved when exported in TypeScript.
|
|---|
| 17 | *
|
|---|
| 18 | * Examples:
|
|---|
| 19 | * - If an identifier is declared as `const x`, then `export {x}` should be preserved.
|
|---|
| 20 | * - If it's declared as `type x`, then `export {x}` should be removed.
|
|---|
| 21 | * - If it's declared as both `const x` and `type x`, then the export should be preserved.
|
|---|
| 22 | * - Classes and enums should be preserved (even though they also introduce types).
|
|---|
| 23 | * - Imported identifiers should be preserved since we don't have enough information to
|
|---|
| 24 | * rule them out. --isolatedModules disallows re-exports, which catches errors here.
|
|---|
| 25 | */
|
|---|
| 26 | function getDeclarationInfo(tokens) {
|
|---|
| 27 | const typeDeclarations = new Set();
|
|---|
| 28 | const valueDeclarations = new Set();
|
|---|
| 29 | for (let i = 0; i < tokens.tokens.length; i++) {
|
|---|
| 30 | const token = tokens.tokens[i];
|
|---|
| 31 | if (token.type === _types.TokenType.name && _tokenizer.isTopLevelDeclaration.call(void 0, token)) {
|
|---|
| 32 | if (token.isType) {
|
|---|
| 33 | typeDeclarations.add(tokens.identifierNameForToken(token));
|
|---|
| 34 | } else {
|
|---|
| 35 | valueDeclarations.add(tokens.identifierNameForToken(token));
|
|---|
| 36 | }
|
|---|
| 37 | }
|
|---|
| 38 | }
|
|---|
| 39 | return {typeDeclarations, valueDeclarations};
|
|---|
| 40 | } exports.default = getDeclarationInfo;
|
|---|