ts-const-value-transformer 0.9.1 → 0.10.0
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/CHANGELOG.md +5 -0
- package/README.md +31 -0
- package/dist/TsProxy.d.mts +105 -0
- package/dist/TsProxy.mjs +1 -0
- package/dist/createPortalTransformer.mjs +2 -1
- package/dist/createPortalTransformerWithTsLs.d.mts +59 -0
- package/dist/createPortalTransformerWithTsLs.mjs +159 -0
- package/dist/createTransformer.mjs +2 -1
- package/dist/index.d.mts +4 -2
- package/dist/index.mjs +4 -2
- package/dist/lsp/SyncLspClient.d.mts +25 -0
- package/dist/lsp/SyncLspClient.mjs +234 -0
- package/dist/lsp/TsLspClient.d.mts +29 -0
- package/dist/lsp/TsLspClient.mjs +271 -0
- package/dist/lsp/lspTransformerUtil.d.mts +1 -0
- package/dist/lsp/lspTransformerUtil.mjs +536 -0
- package/dist/lspTransformer.d.mts +9 -0
- package/dist/lspTransformer.mjs +226 -0
- package/dist/transform.d.mts +6 -5
- package/dist/transform.mjs +100 -299
- package/dist/tscTransformer.d.mts +8 -0
- package/dist/tscTransformer.mjs +377 -0
- package/dist/version.d.mts +1 -1
- package/dist/version.mjs +1 -1
- package/package.json +14 -2
package/CHANGELOG.md
CHANGED
package/README.md
CHANGED
|
@@ -317,6 +317,37 @@ interface CreatePortalTransformerOptions extends TransformOptions {
|
|
|
317
317
|
|
|
318
318
|
If `Promise` cannot be used for some reason, use `createPortalTransformerSync` instead.
|
|
319
319
|
|
|
320
|
+
#### createPortalTransformerWithTsLs: (options?: CreatePortalTransformerWithTsLsOptions) => Promise<PortalTransformerWithTsLs>
|
|
321
|
+
|
|
322
|
+
_Experimental_: Creates 'portal transformer' like [`createPortalTransformer`](#createportaltransformer-options-createportaltransformeroptions--promise), but uses TypeScript language server, including [`tsgo`](https://www.npmjs.com/package/@typescript/native-preview), as type information provider.
|
|
323
|
+
|
|
324
|
+
- To use with `tsgo`, you must install it like `npm install -D @typescript/native-preview`.
|
|
325
|
+
- Currently, `typescript` package is also necessary for parsing source code into AST.
|
|
326
|
+
- Also, tsconfig file must be named with `tsconfig.json` (it is limitation of language server).
|
|
327
|
+
|
|
328
|
+
`CreatePortalTransformerOptions` has a following signature. Also, `TransformOptions` fields, including `ignoreFiles`, can be used.
|
|
329
|
+
|
|
330
|
+
```ts
|
|
331
|
+
export interface CreatePortalTransformerWithTsLsOptions
|
|
332
|
+
extends TransformOptions {
|
|
333
|
+
/**
|
|
334
|
+
* Command to run language server. The first element is used for command name and following elements are used for `argv`.
|
|
335
|
+
* Default is `['npx', 'tsgo', '--lsp', '--stdio']`.
|
|
336
|
+
*/
|
|
337
|
+
command?: readonly string[];
|
|
338
|
+
/** Path to tsconfig.json. If omitted, `tsconfig.json` will be used. **Currently `project` must be path to `tsconfig.json` file name; other than `tsconfig.json` is not supported.** */
|
|
339
|
+
project?: string;
|
|
340
|
+
/** Package path to `typescript` or `typescript` namespace object. This is still necessary to retrieve AST. */
|
|
341
|
+
typescript?: string | typeof tsNamespace;
|
|
342
|
+
/** The current directory for file search. Also affects to `project` option. */
|
|
343
|
+
cwd?: string;
|
|
344
|
+
/** Specifies to cache base (original) source code for check if the input is changed. Default is false. */
|
|
345
|
+
cacheBaseSource?: boolean;
|
|
346
|
+
/** Specifies to cache result source code. Default is true (false for webpack loader). If the latter process has cache system, specifies false to reduce memory usage. */
|
|
347
|
+
cacheResult?: boolean;
|
|
348
|
+
}
|
|
349
|
+
```
|
|
350
|
+
|
|
320
351
|
## Notice
|
|
321
352
|
|
|
322
353
|
Starting from v0.4.0, `unsafeHoistWritableValues` option is introduced. Since TypeScript sometimes narrows non-constant values to literal types such as:
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
export declare namespace ProxyTypes {
|
|
2
|
+
interface TextRange {
|
|
3
|
+
readonly pos: number;
|
|
4
|
+
readonly end: number;
|
|
5
|
+
}
|
|
6
|
+
interface Node {
|
|
7
|
+
readonly pos: number;
|
|
8
|
+
readonly end: number;
|
|
9
|
+
parent?: Node;
|
|
10
|
+
}
|
|
11
|
+
interface SourceFile extends Node {
|
|
12
|
+
readonly text: string;
|
|
13
|
+
}
|
|
14
|
+
interface Expression extends Node {
|
|
15
|
+
_expressionBrand?: any;
|
|
16
|
+
}
|
|
17
|
+
interface UnaryExpression extends Expression {
|
|
18
|
+
_unaryExpressionBrand?: any;
|
|
19
|
+
}
|
|
20
|
+
interface UpdateExpression extends UnaryExpression {
|
|
21
|
+
_updateExpressionBrand?: any;
|
|
22
|
+
}
|
|
23
|
+
interface LeftHandSideExpression extends UpdateExpression {
|
|
24
|
+
_leftHandSideExpressionBrand?: any;
|
|
25
|
+
}
|
|
26
|
+
interface MemberExpression extends LeftHandSideExpression {
|
|
27
|
+
_memberExpressionBrand?: any;
|
|
28
|
+
}
|
|
29
|
+
interface PrimaryExpression extends MemberExpression {
|
|
30
|
+
_primaryExpressionBrand?: any;
|
|
31
|
+
}
|
|
32
|
+
interface Identifier extends PrimaryExpression {
|
|
33
|
+
readonly text: string;
|
|
34
|
+
}
|
|
35
|
+
interface PrivateIdentifier extends PrimaryExpression {
|
|
36
|
+
readonly escapedText: string;
|
|
37
|
+
}
|
|
38
|
+
type MemberName = Identifier | PrivateIdentifier;
|
|
39
|
+
interface ElementAccessExpression extends MemberExpression {
|
|
40
|
+
readonly argumentExpression: Expression;
|
|
41
|
+
}
|
|
42
|
+
interface PropertyAccessExpression extends MemberExpression {
|
|
43
|
+
readonly expression: LeftHandSideExpression;
|
|
44
|
+
readonly name: MemberName;
|
|
45
|
+
}
|
|
46
|
+
interface Type {
|
|
47
|
+
readonly flags: number;
|
|
48
|
+
}
|
|
49
|
+
interface StringLiteralType extends Type {
|
|
50
|
+
readonly value: string;
|
|
51
|
+
}
|
|
52
|
+
interface NumberLiteralType extends Type {
|
|
53
|
+
readonly value: number;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
export interface ApiProxy<TTransformationContext = void> {
|
|
57
|
+
visitEachChild<T extends ProxyTypes.Node>(node: T, visitor: (node: ProxyTypes.Node) => ProxyTypes.Node | readonly ProxyTypes.Node[] | undefined, context: TTransformationContext | undefined): T;
|
|
58
|
+
getNodeText(node: ProxyTypes.Node, sourceFile: ProxyTypes.SourceFile): string;
|
|
59
|
+
getNodeFullText(node: ProxyTypes.Node, sourceFile: ProxyTypes.SourceFile): string;
|
|
60
|
+
appendMultiLineComment<Node extends ProxyTypes.Node>(node: Node, comment: string): Node;
|
|
61
|
+
setTextRange<T extends ProxyTypes.TextRange>(range: T, location: ProxyTypes.TextRange | undefined): T;
|
|
62
|
+
isExpression(node: ProxyTypes.Node): node is ProxyTypes.Expression;
|
|
63
|
+
isAsExpression(node: ProxyTypes.Node): boolean;
|
|
64
|
+
isCallLikeExpression(node: ProxyTypes.Node): boolean;
|
|
65
|
+
isTemplateExpression(node: ProxyTypes.Node): boolean;
|
|
66
|
+
isPropertyAccessExpression(node: ProxyTypes.Node): node is ProxyTypes.PropertyAccessExpression;
|
|
67
|
+
isElementAccessExpression(node: ProxyTypes.Node): node is ProxyTypes.ElementAccessExpression;
|
|
68
|
+
isInterfaceDeclaration(node: ProxyTypes.Node): boolean;
|
|
69
|
+
isTypeAliasDeclaration(node: ProxyTypes.Node): boolean;
|
|
70
|
+
isImportDeclaration(node: ProxyTypes.Node): boolean;
|
|
71
|
+
isTypeOnlyExportDeclaration(node: ProxyTypes.Node): boolean;
|
|
72
|
+
isIdentifier(node: ProxyTypes.Node): node is ProxyTypes.Identifier;
|
|
73
|
+
isComputedPropertyName(node: ProxyTypes.Node): boolean;
|
|
74
|
+
getTypeAtLocation(node: ProxyTypes.Node, sourceFile: ProxyTypes.SourceFile): ProxyTypes.Type | undefined;
|
|
75
|
+
isEnumLiteral(type: ProxyTypes.Type): boolean;
|
|
76
|
+
isStringLiteral(type: ProxyTypes.Type): type is ProxyTypes.StringLiteralType;
|
|
77
|
+
isNumberLiteral(type: ProxyTypes.Type): type is ProxyTypes.NumberLiteralType;
|
|
78
|
+
isBigIntLiteral(type: ProxyTypes.Type): boolean;
|
|
79
|
+
isBooleanLiteral(type: ProxyTypes.Type): boolean;
|
|
80
|
+
isNullType(type: ProxyTypes.Type): boolean;
|
|
81
|
+
isUndefinedType(type: ProxyTypes.Type): boolean;
|
|
82
|
+
typeToString(type: ProxyTypes.Type): string;
|
|
83
|
+
factory?: {
|
|
84
|
+
createIdentifier(text: string): ProxyTypes.Identifier;
|
|
85
|
+
createStringLiteral(value: string): ProxyTypes.PrimaryExpression;
|
|
86
|
+
createNumericLiteral(value: number | string): ProxyTypes.PrimaryExpression;
|
|
87
|
+
createExpressionWithMinusToken(operand: ProxyTypes.Expression): ProxyTypes.Expression;
|
|
88
|
+
createBigIntLiteral(value: string): ProxyTypes.PrimaryExpression;
|
|
89
|
+
createTrue(): ProxyTypes.PrimaryExpression;
|
|
90
|
+
createFalse(): ProxyTypes.PrimaryExpression;
|
|
91
|
+
createNull(): ProxyTypes.PrimaryExpression;
|
|
92
|
+
createParenthesizedExpression(expression: ProxyTypes.Expression): ProxyTypes.Expression;
|
|
93
|
+
createVoidZero(): ProxyTypes.Expression;
|
|
94
|
+
};
|
|
95
|
+
isEnumAccess(node: ProxyTypes.PropertyAccessExpression | ProxyTypes.ElementAccessExpression, sourceFile: ProxyTypes.SourceFile): boolean;
|
|
96
|
+
isEnumIdentifier(node: ProxyTypes.Identifier, sourceFile: ProxyTypes.SourceFile): boolean;
|
|
97
|
+
isExternalReference(node: ProxyTypes.Node, externalNames: ReadonlyArray<string | RegExp>, sourceFile: ProxyTypes.SourceFile): boolean;
|
|
98
|
+
hasPureAnnotation(node: ProxyTypes.Node, sourceFile: ProxyTypes.SourceFile): boolean;
|
|
99
|
+
/** Return `null` if not a target */
|
|
100
|
+
isReadonlyExpression(node: ProxyTypes.Node, sourceFile: ProxyTypes.SourceFile): boolean | null;
|
|
101
|
+
isHoistablePropertyAccess(node: ProxyTypes.PropertyAccessExpression | ProxyTypes.ElementAccessExpression, sourceFile: ProxyTypes.SourceFile): boolean;
|
|
102
|
+
isUndefinedIdentifier(node: ProxyTypes.Identifier, parent: ProxyTypes.Node, sourceFile: ProxyTypes.SourceFile): boolean;
|
|
103
|
+
makeStringLiteralSource(value: string): string;
|
|
104
|
+
getLineStarts(sourceFile: ProxyTypes.SourceFile): readonly number[];
|
|
105
|
+
}
|
package/dist/TsProxy.mjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import * as fs from 'fs';
|
|
2
2
|
import { createRequire } from 'module';
|
|
3
3
|
import * as path from 'path';
|
|
4
|
-
import { getIgnoreFilesFunction
|
|
4
|
+
import { getIgnoreFilesFunction } from './transform.mjs';
|
|
5
|
+
import { transformAndPrintSourceWithMap } from './tscTransformer.mjs';
|
|
5
6
|
const require = createRequire(import.meta.url);
|
|
6
7
|
function optionsToString(options) {
|
|
7
8
|
return JSON.stringify(options, (key, value) => {
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import type { RawSourceMap } from 'source-map';
|
|
2
|
+
import type * as tsNamespace from 'typescript';
|
|
3
|
+
import type { PortalTransformerResult, PortalTransformerResultNonNull } from './createPortalTransformer.mjs';
|
|
4
|
+
import { type TransformOptions } from './transform.mjs';
|
|
5
|
+
export interface CreatePortalTransformerWithTsLsOptions extends TransformOptions {
|
|
6
|
+
/**
|
|
7
|
+
* Command to run language server. The first element is used for command name and following elements are used for `argv`.
|
|
8
|
+
* Default is `['npx', 'tsgo', '--lsp', '--stdio']`.
|
|
9
|
+
*/
|
|
10
|
+
command?: readonly string[];
|
|
11
|
+
/** Path to tsconfig.json. If omitted, `tsconfig.json` will be used. **Currently `project` must be path to `tsconfig.json` file name; other than `tsconfig.json` is not supported.** */
|
|
12
|
+
project?: string;
|
|
13
|
+
/** Package path to `typescript` or `typescript` namespace object. This is still necessary to retrieve AST. */
|
|
14
|
+
typescript?: string | typeof tsNamespace;
|
|
15
|
+
/** The current directory for file search. Also affects to `project` option. */
|
|
16
|
+
cwd?: string;
|
|
17
|
+
/** Specifies to cache base (original) source code for check if the input is changed. Default is false. */
|
|
18
|
+
cacheBaseSource?: boolean;
|
|
19
|
+
/** Specifies to cache result source code. Default is true (false for webpack loader). If the latter process has cache system, specifies false to reduce memory usage. */
|
|
20
|
+
cacheResult?: boolean;
|
|
21
|
+
}
|
|
22
|
+
export interface PortalTransformerWithTsLs {
|
|
23
|
+
/** The `typescript` namespace object */
|
|
24
|
+
readonly ts: typeof tsNamespace;
|
|
25
|
+
/** Clears transformed cache. */
|
|
26
|
+
clearCache(): void;
|
|
27
|
+
/**
|
|
28
|
+
* Performs transformation.
|
|
29
|
+
* @param content Base source code. If null, uses loaded source code in the TS project.
|
|
30
|
+
* @param fileName Base file name (If not included in the TS project, transformation will not be performed.)
|
|
31
|
+
* @param sourceMap Base source map if exists
|
|
32
|
+
* @param options Transform options (addition to `options` passed to `createPortalTransformer`)
|
|
33
|
+
* @returns Tuple of new source code and source map. Source map may be undefined if source code is unchanged.
|
|
34
|
+
*/
|
|
35
|
+
transform(content: string, fileName: string, sourceMap?: string | RawSourceMap | null, options?: TransformOptions): PortalTransformerResultNonNull;
|
|
36
|
+
/**
|
|
37
|
+
* Performs transformation.
|
|
38
|
+
* @param content Base source code. If null, uses loaded source code in the TS project.
|
|
39
|
+
* @param fileName Base file name (If not included in the TS project, transformation will not be performed.)
|
|
40
|
+
* @param sourceMap Base source map if exists
|
|
41
|
+
* @param options Transform options (addition to `options` passed to `createPortalTransformer`)
|
|
42
|
+
* @returns Tuple of new source code and source map. Source map may be undefined if source code is unchanged.
|
|
43
|
+
*/
|
|
44
|
+
transform(content: string | null, fileName: string, sourceMap?: string | RawSourceMap | null, options?: TransformOptions): PortalTransformerResult;
|
|
45
|
+
/**
|
|
46
|
+
* Closes the LSP client.
|
|
47
|
+
*/
|
|
48
|
+
close(): void;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Creates the new portal transformer instance for the TS project using language server.
|
|
52
|
+
* After creation, the transformation process can be performed by calling {@link PortalTransformerWithTsLs.transform}.
|
|
53
|
+
*/
|
|
54
|
+
export default function createPortalTransformerWithTsLs(options?: CreatePortalTransformerWithTsLsOptions): Promise<PortalTransformerWithTsLs>;
|
|
55
|
+
/**
|
|
56
|
+
* Creates the new portal transformer instance for the TS project (using `require` function).
|
|
57
|
+
* After creation, the transformation process can be performed by calling {@link PortalTransformerWithTsLs.transform}.
|
|
58
|
+
*/
|
|
59
|
+
export declare function createPortalTransformerSyncWithTsLs(options?: CreatePortalTransformerWithTsLsOptions): PortalTransformerWithTsLs;
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
import * as fs from 'fs';
|
|
2
|
+
import { createRequire } from 'module';
|
|
3
|
+
import * as path from 'path';
|
|
4
|
+
import TsLspClient from './lsp/TsLspClient.mjs';
|
|
5
|
+
import { transformAndPrintSourceWithMap } from './lspTransformer.mjs';
|
|
6
|
+
import { getIgnoreFilesFunction } from './transform.mjs';
|
|
7
|
+
const require = createRequire(import.meta.url);
|
|
8
|
+
function optionsToString(options) {
|
|
9
|
+
return JSON.stringify(options, (key, value) => {
|
|
10
|
+
if (typeof value === 'function' || value instanceof RegExp) {
|
|
11
|
+
return value.toString();
|
|
12
|
+
}
|
|
13
|
+
if (key === 'typescript' && typeof value === 'object' && value != null) {
|
|
14
|
+
return '[object typescript]';
|
|
15
|
+
}
|
|
16
|
+
return value;
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
function createPortalTransformerImpl(options, ts) {
|
|
20
|
+
const project = options.project ?? 'tsconfig.json';
|
|
21
|
+
if (path.basename(project) !== 'tsconfig.json') {
|
|
22
|
+
throw new Error(`options.project must be 'tsconfig.json' due to restriction of language-server (actual: "${project}")`);
|
|
23
|
+
}
|
|
24
|
+
const commandArray = options.command ?? ['npx', 'tsgo', '--lsp', '--stdio'];
|
|
25
|
+
if (commandArray.length < 1) {
|
|
26
|
+
throw new Error(`options.command must have at least one element`);
|
|
27
|
+
}
|
|
28
|
+
const ignoreFiles = getIgnoreFilesFunction(options.ignoreFiles);
|
|
29
|
+
const cwd = options.cwd ?? process.cwd();
|
|
30
|
+
const cacheBaseSource = options.cacheBaseSource ?? false;
|
|
31
|
+
const cacheResult = options.cacheResult ?? true;
|
|
32
|
+
const workspaceFolder = path.dirname(path.resolve(cwd, project));
|
|
33
|
+
const client = new TsLspClient(commandArray[0], commandArray.slice(1));
|
|
34
|
+
let isInitialized = false;
|
|
35
|
+
const cache = new Map();
|
|
36
|
+
const sourceFileMap = new Map();
|
|
37
|
+
const getSourceFile = (fileName, content) => {
|
|
38
|
+
let sourceFile = sourceFileMap.get(fileName);
|
|
39
|
+
if (!sourceFile) {
|
|
40
|
+
if (content == null) {
|
|
41
|
+
content = fs.readFileSync(fileName, 'utf-8');
|
|
42
|
+
}
|
|
43
|
+
sourceFile = ts.createSourceFile(fileName, content, ts.ScriptTarget.Latest, true);
|
|
44
|
+
sourceFileMap.set(fileName, sourceFile);
|
|
45
|
+
client.openDocument(fileName, content);
|
|
46
|
+
}
|
|
47
|
+
return sourceFile;
|
|
48
|
+
};
|
|
49
|
+
const instance = {
|
|
50
|
+
ts,
|
|
51
|
+
clearCache: () => cache.clear(),
|
|
52
|
+
transform: (content, fileName, sourceMap, individualOptions) => {
|
|
53
|
+
const individualOptionsJson = optionsToString(individualOptions ?? {});
|
|
54
|
+
if (cacheResult) {
|
|
55
|
+
const cachedData = cache.get(fileName);
|
|
56
|
+
if (cachedData &&
|
|
57
|
+
(!cacheBaseSource || cachedData.content === content) &&
|
|
58
|
+
cachedData.optJson === individualOptionsJson) {
|
|
59
|
+
return cachedData.result;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
63
|
+
const rawSourceMap = typeof sourceMap === 'string'
|
|
64
|
+
? JSON.parse(sourceMap)
|
|
65
|
+
: (sourceMap ?? void 0);
|
|
66
|
+
if (ignoreFiles(fileName)) {
|
|
67
|
+
return [content, rawSourceMap];
|
|
68
|
+
}
|
|
69
|
+
if (!isInitialized) {
|
|
70
|
+
client.initialize(workspaceFolder);
|
|
71
|
+
}
|
|
72
|
+
let sourceFile = sourceFileMap.get(fileName);
|
|
73
|
+
if (!sourceFile) {
|
|
74
|
+
sourceFile = getSourceFile(fileName, content);
|
|
75
|
+
}
|
|
76
|
+
// If input content is changed, replace it
|
|
77
|
+
else if (content != null && sourceFile.text !== content) {
|
|
78
|
+
sourceFile.update(content, {
|
|
79
|
+
span: { start: 0, length: sourceFile.end },
|
|
80
|
+
newLength: content.length,
|
|
81
|
+
});
|
|
82
|
+
sourceFile.text = content;
|
|
83
|
+
}
|
|
84
|
+
if (!isInitialized) {
|
|
85
|
+
client.waitForFirstDiagnosticsReceived();
|
|
86
|
+
isInitialized = true;
|
|
87
|
+
}
|
|
88
|
+
const result = transformAndPrintSourceWithMap(sourceFile, client, getSourceFile, fileName, { ...options, ...individualOptions, ts }, rawSourceMap);
|
|
89
|
+
if (sourceFile.text === result[0]) {
|
|
90
|
+
result[1] = undefined;
|
|
91
|
+
}
|
|
92
|
+
if (cacheResult) {
|
|
93
|
+
// This forces to concatenate strings into flatten one, to reduce object trees for ConsString
|
|
94
|
+
void (result[0] | 0);
|
|
95
|
+
const json = result[1];
|
|
96
|
+
if (json) {
|
|
97
|
+
void (json.mappings | 0);
|
|
98
|
+
}
|
|
99
|
+
cache.set(fileName, {
|
|
100
|
+
content: cacheBaseSource ? content : '',
|
|
101
|
+
optJson: individualOptionsJson,
|
|
102
|
+
result,
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
client.closeDocument(fileName);
|
|
106
|
+
return result;
|
|
107
|
+
},
|
|
108
|
+
close: () => {
|
|
109
|
+
client.exit();
|
|
110
|
+
},
|
|
111
|
+
};
|
|
112
|
+
return instance;
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Creates the new portal transformer instance for the TS project using language server.
|
|
116
|
+
* After creation, the transformation process can be performed by calling {@link PortalTransformerWithTsLs.transform}.
|
|
117
|
+
*/
|
|
118
|
+
export default async function createPortalTransformerWithTsLs(options = {}) {
|
|
119
|
+
let ts;
|
|
120
|
+
if (options.typescript != null) {
|
|
121
|
+
if (typeof options.typescript === 'string') {
|
|
122
|
+
// Use eval to avoid webpack warnings
|
|
123
|
+
// eslint-disable-next-line no-eval
|
|
124
|
+
ts = (await eval('import(options.typescript)'));
|
|
125
|
+
}
|
|
126
|
+
else {
|
|
127
|
+
ts = options.typescript;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
else if (options.ts != null) {
|
|
131
|
+
ts = options.ts;
|
|
132
|
+
}
|
|
133
|
+
else {
|
|
134
|
+
ts = await import('typescript');
|
|
135
|
+
}
|
|
136
|
+
return createPortalTransformerImpl(options, ts);
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Creates the new portal transformer instance for the TS project (using `require` function).
|
|
140
|
+
* After creation, the transformation process can be performed by calling {@link PortalTransformerWithTsLs.transform}.
|
|
141
|
+
*/
|
|
142
|
+
export function createPortalTransformerSyncWithTsLs(options = {}) {
|
|
143
|
+
let ts;
|
|
144
|
+
if (options.typescript != null) {
|
|
145
|
+
if (typeof options.typescript === 'string') {
|
|
146
|
+
ts = require(options.typescript);
|
|
147
|
+
}
|
|
148
|
+
else {
|
|
149
|
+
ts = options.typescript;
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
else if (options.ts != null) {
|
|
153
|
+
ts = options.ts;
|
|
154
|
+
}
|
|
155
|
+
else {
|
|
156
|
+
ts = require('typescript');
|
|
157
|
+
}
|
|
158
|
+
return createPortalTransformerImpl(options, ts);
|
|
159
|
+
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { getIgnoreFilesFunction
|
|
1
|
+
import { getIgnoreFilesFunction } from './transform.mjs';
|
|
2
|
+
import { transformSource } from './tscTransformer.mjs';
|
|
2
3
|
export default function createTransformer(program,
|
|
3
4
|
// for ttypescript and ts-patch
|
|
4
5
|
config,
|
package/dist/index.d.mts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import createPortalTransformer, { createPortalTransformerSync, type CreatePortalTransformerOptions, type PortalTransformer, type PortalTransformerResult, type PortalTransformerResultNonNull } from './createPortalTransformer.mjs';
|
|
2
|
+
import createPortalTransformerWithTsLs, { createPortalTransformerSyncWithTsLs, type CreatePortalTransformerWithTsLsOptions, type PortalTransformerWithTsLs } from './createPortalTransformerWithTsLs.mjs';
|
|
2
3
|
import createTransformer from './createTransformer.mjs';
|
|
3
4
|
import version from './version.mjs';
|
|
4
|
-
export {
|
|
5
|
-
export {
|
|
5
|
+
export { printSourceWithProxy, printSourceWithMapWithProxy, transformAndPrintSourceWithProxy, transformAndPrintSourceWithMapWithProxy, transformSourceWithProxy, type TransformOptions, } from './transform.mjs';
|
|
6
|
+
export { printSource, printSourceWithMap, transformAndPrintSource, transformAndPrintSourceWithMap, transformSource, } from './tscTransformer.mjs';
|
|
7
|
+
export { createPortalTransformer, createPortalTransformerSync, createTransformer, type CreatePortalTransformerOptions, type PortalTransformer, type PortalTransformerResult, type PortalTransformerResultNonNull, createPortalTransformerWithTsLs, createPortalTransformerSyncWithTsLs, type CreatePortalTransformerWithTsLsOptions, type PortalTransformerWithTsLs, version, };
|
package/dist/index.mjs
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import createPortalTransformer, { createPortalTransformerSync, } from './createPortalTransformer.mjs';
|
|
2
|
+
import createPortalTransformerWithTsLs, { createPortalTransformerSyncWithTsLs, } from './createPortalTransformerWithTsLs.mjs';
|
|
2
3
|
import createTransformer from './createTransformer.mjs';
|
|
3
4
|
import version from './version.mjs';
|
|
4
|
-
export {
|
|
5
|
-
export {
|
|
5
|
+
export { printSourceWithProxy, printSourceWithMapWithProxy, transformAndPrintSourceWithProxy, transformAndPrintSourceWithMapWithProxy, transformSourceWithProxy, } from './transform.mjs';
|
|
6
|
+
export { printSource, printSourceWithMap, transformAndPrintSource, transformAndPrintSourceWithMap, transformSource, } from './tscTransformer.mjs';
|
|
7
|
+
export { createPortalTransformer, createPortalTransformerSync, createTransformer, createPortalTransformerWithTsLs, createPortalTransformerSyncWithTsLs, version, };
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export default class SyncLspClient {
|
|
2
|
+
/** process */
|
|
3
|
+
private readonly _p;
|
|
4
|
+
private _id;
|
|
5
|
+
/** received data */
|
|
6
|
+
private readonly _r;
|
|
7
|
+
/** server message handlers */
|
|
8
|
+
private readonly _s;
|
|
9
|
+
/** notification handlers */
|
|
10
|
+
private readonly _n;
|
|
11
|
+
/** last buffer */
|
|
12
|
+
private _l;
|
|
13
|
+
/** encoding */
|
|
14
|
+
private readonly _e;
|
|
15
|
+
constructor(command: string, argv: string[], encoding?: BufferEncoding);
|
|
16
|
+
private sendRaw;
|
|
17
|
+
sendMessage(method: string, params?: object): number | string;
|
|
18
|
+
notifyMessage(method: string, params?: object): void;
|
|
19
|
+
private pushReceived;
|
|
20
|
+
pumpMessage(flushOnly?: boolean): boolean;
|
|
21
|
+
receiveMessage(id: number | string): object | null | undefined;
|
|
22
|
+
registerServerMessageHandler(method: string, callback: (method: string, params: object | undefined) => object | null | undefined, once?: boolean): () => void;
|
|
23
|
+
registerNotificationHandler(method: string, callback: (method: string, params: object | undefined) => void, once?: boolean): () => void;
|
|
24
|
+
close(): void;
|
|
25
|
+
}
|