typescript-to-lua 1.1.0 → 1.1.1
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/cli/parse.d.ts +1 -1
- package/dist/cli/parse.js +14 -0
- package/dist/transformation/utils/export.d.ts +3 -2
- package/dist/transformation/utils/export.js +10 -3
- package/dist/transformation/visitors/class/index.js +8 -1
- package/dist/transformation/visitors/modules/export.js +3 -4
- package/dist/transpilation/resolve.js +1 -1
- package/package.json +1 -1
package/dist/cli/parse.d.ts
CHANGED
|
@@ -13,7 +13,7 @@ interface CommandLineOptionOfEnum extends CommandLineOptionBase {
|
|
|
13
13
|
choices: string[];
|
|
14
14
|
}
|
|
15
15
|
interface CommandLineOptionOfPrimitive extends CommandLineOptionBase {
|
|
16
|
-
type: "boolean" | "string" | "object";
|
|
16
|
+
type: "boolean" | "string" | "object" | "array";
|
|
17
17
|
}
|
|
18
18
|
declare type CommandLineOption = CommandLineOptionOfEnum | CommandLineOptionOfPrimitive;
|
|
19
19
|
export declare const optionDeclarations: CommandLineOption[];
|
package/dist/cli/parse.js
CHANGED
|
@@ -59,6 +59,11 @@ exports.optionDeclarations = [
|
|
|
59
59
|
description: "Provide verbose output useful for diagnosing problems.",
|
|
60
60
|
type: "boolean",
|
|
61
61
|
},
|
|
62
|
+
{
|
|
63
|
+
name: "noResolvePaths",
|
|
64
|
+
description: "An array of paths that tstl should not resolve and keep as-is.",
|
|
65
|
+
type: "array",
|
|
66
|
+
},
|
|
62
67
|
];
|
|
63
68
|
function updateParsedConfigFile(parsedConfigFile) {
|
|
64
69
|
let hasRootLevelOptions = false;
|
|
@@ -162,6 +167,15 @@ function readValue(option, value) {
|
|
|
162
167
|
}
|
|
163
168
|
return { value };
|
|
164
169
|
}
|
|
170
|
+
case "array": {
|
|
171
|
+
if (!Array.isArray(value)) {
|
|
172
|
+
return {
|
|
173
|
+
value: undefined,
|
|
174
|
+
error: cliDiagnostics.compilerOptionRequiresAValueOfType(option.name, option.type),
|
|
175
|
+
};
|
|
176
|
+
}
|
|
177
|
+
return { value };
|
|
178
|
+
}
|
|
165
179
|
case "enum": {
|
|
166
180
|
if (typeof value !== "string") {
|
|
167
181
|
return {
|
|
@@ -2,8 +2,8 @@ import * as ts from "typescript";
|
|
|
2
2
|
import * as lua from "../../LuaAST";
|
|
3
3
|
import { TransformationContext } from "../context";
|
|
4
4
|
export declare function hasDefaultExportModifier(node: ts.Node): boolean;
|
|
5
|
-
export declare
|
|
6
|
-
export declare const createDefaultExportStringLiteral: (original
|
|
5
|
+
export declare function hasExportModifier(node: ts.Node): boolean;
|
|
6
|
+
export declare const createDefaultExportStringLiteral: (original?: ts.Node | undefined) => lua.StringLiteral;
|
|
7
7
|
export declare function getExportedSymbolDeclaration(symbol: ts.Symbol): ts.Declaration | undefined;
|
|
8
8
|
export declare function getSymbolFromIdentifier(context: TransformationContext, identifier: lua.Identifier): ts.Symbol | undefined;
|
|
9
9
|
export declare function getIdentifierExportScope(context: TransformationContext, identifier: lua.Identifier): ts.SourceFile | ts.ModuleDeclaration | undefined;
|
|
@@ -14,3 +14,4 @@ export declare function isSymbolExported(context: TransformationContext, symbol:
|
|
|
14
14
|
export declare function isSymbolExportedFromScope(context: TransformationContext, symbol: ts.Symbol, scope: ts.SourceFile | ts.ModuleDeclaration): boolean;
|
|
15
15
|
export declare function addExportToIdentifier(context: TransformationContext, identifier: lua.Identifier): lua.AssignmentLeftHandSideExpression;
|
|
16
16
|
export declare function createExportedIdentifier(context: TransformationContext, identifier: lua.Identifier, exportScope?: ts.SourceFile | ts.ModuleDeclaration): lua.AssignmentLeftHandSideExpression;
|
|
17
|
+
export declare function createDefaultExportExpression(node: ts.Node): lua.AssignmentLeftHandSideExpression;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createExportedIdentifier = exports.addExportToIdentifier = exports.isSymbolExportedFromScope = exports.isSymbolExported = exports.getDependenciesOfSymbol = exports.getExportedSymbolsFromScope = exports.getSymbolExportScope = exports.getIdentifierExportScope = exports.getSymbolFromIdentifier = exports.getExportedSymbolDeclaration = exports.createDefaultExportStringLiteral = exports.
|
|
3
|
+
exports.createDefaultExportExpression = exports.createExportedIdentifier = exports.addExportToIdentifier = exports.isSymbolExportedFromScope = exports.isSymbolExported = exports.getDependenciesOfSymbol = exports.getExportedSymbolsFromScope = exports.getSymbolExportScope = exports.getIdentifierExportScope = exports.getSymbolFromIdentifier = exports.getExportedSymbolDeclaration = exports.createDefaultExportStringLiteral = exports.hasExportModifier = exports.hasDefaultExportModifier = void 0;
|
|
4
4
|
const ts = require("typescript");
|
|
5
5
|
const lua = require("../../LuaAST");
|
|
6
6
|
const namespace_1 = require("../visitors/namespace");
|
|
@@ -12,8 +12,11 @@ function hasDefaultExportModifier(node) {
|
|
|
12
12
|
return ((_a = node.modifiers) !== null && _a !== void 0 ? _a : []).some(modifier => modifier.kind === ts.SyntaxKind.DefaultKeyword);
|
|
13
13
|
}
|
|
14
14
|
exports.hasDefaultExportModifier = hasDefaultExportModifier;
|
|
15
|
-
|
|
16
|
-
|
|
15
|
+
function hasExportModifier(node) {
|
|
16
|
+
var _a;
|
|
17
|
+
return ((_a = node.modifiers) !== null && _a !== void 0 ? _a : []).some(modifier => modifier.kind === ts.SyntaxKind.ExportKeyword);
|
|
18
|
+
}
|
|
19
|
+
exports.hasExportModifier = hasExportModifier;
|
|
17
20
|
const createDefaultExportStringLiteral = (original) => lua.createStringLiteral("default", original);
|
|
18
21
|
exports.createDefaultExportStringLiteral = createDefaultExportStringLiteral;
|
|
19
22
|
function getExportedSymbolDeclaration(symbol) {
|
|
@@ -103,4 +106,8 @@ function createExportedIdentifier(context, identifier, exportScope) {
|
|
|
103
106
|
return lua.createTableIndexExpression(exportTable, lua.createStringLiteral(identifier.text));
|
|
104
107
|
}
|
|
105
108
|
exports.createExportedIdentifier = createExportedIdentifier;
|
|
109
|
+
function createDefaultExportExpression(node) {
|
|
110
|
+
return lua.createTableIndexExpression((0, lua_ast_1.createExportsIdentifier)(), (0, exports.createDefaultExportStringLiteral)(node), node);
|
|
111
|
+
}
|
|
112
|
+
exports.createDefaultExportExpression = createDefaultExportExpression;
|
|
106
113
|
//# sourceMappingURL=export.js.map
|
|
@@ -22,7 +22,7 @@ const utils_2 = require("./utils");
|
|
|
22
22
|
const transformClassDeclaration = (declaration, context) => {
|
|
23
23
|
// If declaration is a default export, transform to export variable assignment instead
|
|
24
24
|
if ((0, export_1.hasDefaultExportModifier)(declaration)) {
|
|
25
|
-
const left = (0, export_1.
|
|
25
|
+
const left = (0, export_1.createDefaultExportExpression)(declaration);
|
|
26
26
|
const right = transformClassAsExpression(declaration, context);
|
|
27
27
|
return [lua.createAssignmentStatement(left, right, declaration)];
|
|
28
28
|
}
|
|
@@ -152,6 +152,13 @@ function transformClassLikeDeclaration(classDeclaration, context, nameOverride)
|
|
|
152
152
|
const decoratingExpression = (0, decorators_1.createDecoratingExpression)(context, classDeclaration.kind, classDeclaration.decorators.map(d => (0, decorators_1.transformDecoratorExpression)(context, d)), localClassName);
|
|
153
153
|
const decoratingStatement = lua.createAssignmentStatement(localClassName, decoratingExpression);
|
|
154
154
|
result.push(decoratingStatement);
|
|
155
|
+
if ((0, export_1.hasExportModifier)(classDeclaration)) {
|
|
156
|
+
const exportExpression = (0, export_1.hasDefaultExportModifier)(classDeclaration)
|
|
157
|
+
? (0, export_1.createDefaultExportExpression)(classDeclaration)
|
|
158
|
+
: (0, export_1.createExportedIdentifier)(context, className);
|
|
159
|
+
const classAssignment = lua.createAssignmentStatement(exportExpression, localClassName);
|
|
160
|
+
result.push(classAssignment);
|
|
161
|
+
}
|
|
155
162
|
}
|
|
156
163
|
superInfo.pop();
|
|
157
164
|
return { statements: result, name: className };
|
|
@@ -72,10 +72,9 @@ function transformExportSpecifier(context, node) {
|
|
|
72
72
|
const exportedIdentifier = node.propertyName ? node.propertyName : node.name;
|
|
73
73
|
const exportedExpression = (0, literal_1.createShorthandIdentifier)(context, exportedSymbol, exportedIdentifier);
|
|
74
74
|
const isDefault = isDefaultExportSpecifier(node);
|
|
75
|
-
const
|
|
76
|
-
? (0, export_1.
|
|
77
|
-
: (0, identifier_1.transformIdentifier)(context, node.name);
|
|
78
|
-
const exportAssignmentLeftHandSide = (0, export_1.createExportedIdentifier)(context, identifierToExport);
|
|
75
|
+
const exportAssignmentLeftHandSide = isDefault
|
|
76
|
+
? (0, export_1.createDefaultExportExpression)(node)
|
|
77
|
+
: (0, export_1.createExportedIdentifier)(context, (0, identifier_1.transformIdentifier)(context, node.name));
|
|
79
78
|
return lua.createAssignmentStatement(exportAssignmentLeftHandSide, exportedExpression, node);
|
|
80
79
|
}
|
|
81
80
|
function transformExportSpecifiersFrom(context, statement, moduleSpecifier, exportSpecifiers) {
|
|
@@ -244,7 +244,7 @@ function isBuildModeLibrary(program) {
|
|
|
244
244
|
function findRequiredPaths(code) {
|
|
245
245
|
// Find all require("<path>") paths in a lua code string
|
|
246
246
|
const paths = [];
|
|
247
|
-
const pattern = /(^|\s|;|=)require\("(
|
|
247
|
+
const pattern = /(^|\s|;|=)require\("(.+?)"\)/g;
|
|
248
248
|
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
249
249
|
let match;
|
|
250
250
|
while ((match = pattern.exec(code))) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "typescript-to-lua",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.1",
|
|
4
4
|
"description": "A generic TypeScript to Lua transpiler. Write your code in TypeScript and publish Lua!",
|
|
5
5
|
"repository": "https://github.com/TypeScriptToLua/TypeScriptToLua",
|
|
6
6
|
"homepage": "https://typescripttolua.github.io/",
|