Skip to content
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

upgrade to latest TSTL #383

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 44 additions & 28 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
"@types/unzipper": "^0.10.4",
"@typescript-eslint/eslint-plugin": "^5.8.0",
"@typescript-eslint/parser": "^5.8.0",
"@typescript-to-lua/language-extensions": "^1.0.0",
"concat-stream": "^2.0.0",
"eslint": "^8.5.0",
"jest": "^27.4.5",
Expand All @@ -55,14 +56,14 @@
"prettier": "^2.5.1",
"ts-jest": "^27.1.2",
"ts-node": "^10.4.0",
"typescript": "~4.5.2"
"typescript": "^4.5.2"
},
"dependencies": {
"enquirer": "^2.3.6",
"js-yaml": "^4.1.0",
"json5": "^2.2.0",
"jsonschema": "^1.4.0",
"typescript-to-lua": "^1.0.1",
"typescript-to-lua": "^1.10.1",
"unzipper": "^0.10.11",
"xml-js": "^1.6.11"
}
Expand Down
14 changes: 11 additions & 3 deletions src/ast/prepareImports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,11 @@ function resolveImportsFromAnotherModules(
createIdentifier(
declarationName.text,
declarationName,
getIdentifierSymbolId(context, declarationName),
getIdentifierSymbolId(
context,
declarationName,
undefined,
),
),
createIdentifier(
`function(...) return exports["${resourceName}"]:${declarationName.text}(...) end`,
Expand Down Expand Up @@ -214,7 +218,11 @@ const prepareGlobalImports: FunctionVisitor<ts.ImportDeclaration> = function (
createIdentifier(
value.name.text,
value.name,
getIdentifierSymbolId(context, value.name),
getIdentifierSymbolId(
context,
value.name,
undefined,
),
),
createIdentifier(value.propertyName?.text ?? 'nil'),
value,
Expand All @@ -235,7 +243,7 @@ const prepareGlobalImports: FunctionVisitor<ts.ImportDeclaration> = function (
createIdentifier(
value.name.text,
value.name,
getIdentifierSymbolId(context, value.name),
getIdentifierSymbolId(context, value.name, undefined),
),
createIdentifier(getGlobalsTableName()),
value,
Expand Down
2 changes: 1 addition & 1 deletion src/ast/removeExportDeclaration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const removeExportDeclaration: FunctionVisitor<ts.ExportDeclaration> =
}

const expression = assignment.left[0] as TableIndexExpression;
if (expression.table.kind !== 28) {
if (expression.table.kind !== SyntaxKind.Identifier) {
continue;
}

Expand Down
6 changes: 5 additions & 1 deletion src/ast/removeImports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,11 @@ const removeImportDeclarations: FunctionVisitor<ts.ImportDeclaration> =
createIdentifier(
name,
namespaceImport.name,
getIdentifierSymbolId(context, namespaceImport.name),
getIdentifierSymbolId(
context,
namespaceImport.name,
undefined,
),
),
createIdentifier(getGlobalsTableName()),
node,
Expand Down
13 changes: 12 additions & 1 deletion src/compiler/compile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ export function compileLuaLib(
...extendOptions(options, meta, data),
rootDir: path.dirname(getEmptyTsFilePath()),
outDir: data.outDir,
luaLibImport: LuaLibImportKind.Always,
luaLibImport: LuaLibImportKind.Require,
};

if (options.tstlVerbose) {
Expand All @@ -182,6 +182,17 @@ export function compileLuaLib(
return;
}

const returnRegexp =
/return\s({\n(?:\s+?__TS__\w+(?:\s=|,)){2}[\W\w]+})/gi;
const returnValue = dataWrite.match(returnRegexp)?.[0];
const returnScript =
'for key, value in pairs(MTA_EXPORTS) do\n\t_G[key] = value\nend';
if (!returnValue) throw new Error('cannot replace exports');
dataWrite = dataWrite.replace(
returnRegexp,
`local MTA_EXPORTS = $1\n\n${returnScript}`,
);

return writeData(
fileName,
dataWrite,
Expand Down
4 changes: 2 additions & 2 deletions src/compiler/validate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ const validateLuaTarget: ValidatorFunction = function (options) {
};

const validateLuaLibImport: ValidatorFunction = function (options) {
if (options.luaLibImport === 'always') {
if (options.luaLibImport === 'require') {
return [];
}

return [
simpleTsDiagnostic(
'Expected luaLibImport property value: "always". ' +
'Expected luaLibImport property value: "require". ' +
'Check the tsconfig.json\n' +
'https://github.com/mtasa-typescript/mtasa-lua-utils/blob/master/tsconfig.json',
DiagnosticCategory.Warning,
Expand Down
4 changes: 4 additions & 0 deletions src/debug.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { buildProject } from './cli/build';

const filepath = 'src/tests/resources.spec/importPlugin/mtasa-meta.yml';
buildProject(['--meta', filepath, '--project', 'src/tests/tsconfig.json']);
6 changes: 3 additions & 3 deletions src/tests/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"$schema": "https://raw.githubusercontent.com/TypeScriptToLua/vscode-typescript-to-lua/master/tsconfig-schema.json",
"$schema": "https://raw.githubusercontent.com/TypeScriptToLua/TypeScriptToLua/master/tsconfig-schema.json",
"compilerOptions": {
"target": "ES6",
"lib": ["es6"],
Expand All @@ -17,7 +17,7 @@
"stripInternal": true,
"baseUrl": ".",
"types": [
"typescript-to-lua/language-extensions",
"@typescript-to-lua/language-extensions",
"@types/jest",
"@types/node"
]
Expand All @@ -30,7 +30,7 @@
// Provides debug.traceback function
"sourceMapTraceback": true,
// Lualib should be always included in the resource
"luaLibImport": "always"
"luaLibImport": "require"
},
"include": ["src/**/*"],
"exclude": ["src/tests/**/*"]
Expand Down
5 changes: 2 additions & 3 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"$schema": "https://raw.githubusercontent.com/TypeScriptToLua/vscode-typescript-to-lua/master/tsconfig-schema.json",
"$schema": "https://raw.githubusercontent.com/TypeScriptToLua/TypeScriptToLua/master/tsconfig-schema.json",
"compilerOptions": {
"target": "ES6",
"lib": ["es6"],
Expand All @@ -25,8 +25,7 @@
"noImplicitSelf": true,
// Provides debug.traceback function
"sourceMapTraceback": true,
// Lualib should be always included in the resource
"luaLibImport": "always",
"luaLibImport": "require",
// Verbose output
"tstlVerbose": true
},
Expand Down