diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 90ad7fc..ee3ee5d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -9,10 +9,10 @@ jobs: steps: - uses: actions/checkout@v2 - - name: Use Node.js 12 + - name: Use Node.js 16 uses: actions/setup-node@v1 with: - node-version: 12 + node-version: 16 - run: npm ci - run: npm run lint @@ -22,9 +22,9 @@ jobs: steps: - uses: actions/checkout@v2 - - name: Use Node.js 12 + - name: Use Node.js 16 uses: actions/setup-node@v1 with: - node-version: 12 + node-version: 16 - run: npm ci - run: npm test diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index d4f55c0..7536a34 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -11,10 +11,10 @@ jobs: steps: - uses: actions/checkout@v2 - - name: Use Node.js 12.13.1 + - name: Use Node.js 16 uses: actions/setup-node@v1 with: - node-version: 12.13.1 + node-version: 16 registry-url: 'https://registry.npmjs.org' - run: npm ci - run: npm test diff --git a/.gitignore b/.gitignore index 105410e..041b062 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ node_modules .vscode *.log *.js +test/testproject/*.lua diff --git a/core/index-5.0.d.ts b/core/index-5.0.d.ts index 4ffe7c8..0cc083b 100644 --- a/core/index-5.0.d.ts +++ b/core/index-5.0.d.ts @@ -1,4 +1,4 @@ -/// +/// /// /// diff --git a/core/index.d.ts b/core/index.d.ts index 6d73c6a..96d49da 100644 --- a/core/index.d.ts +++ b/core/index.d.ts @@ -1,4 +1,4 @@ -/// +/// /// /// diff --git a/package-lock.json b/package-lock.json index 2f1027f..bd22adc 100644 --- a/package-lock.json +++ b/package-lock.json @@ -5,19 +5,19 @@ "requires": true, "packages": { "": { + "name": "lua-types", "version": "2.12.2", "license": "MIT", "devDependencies": { "@types/jest": "^26.0.20", "@types/node": "^14.14.34", + "@typescript-to-lua/language-extensions": "^1.0.0", "jest": "^26.6.3", "jest-circus": "^26.6.3", "prettier": "^2.0.5", "ts-jest": "^26.5.3", - "typescript-to-lua": "^1.0.1" - }, - "peerDependencies": { - "typescript-to-lua": "^1.0.0" + "typescript": "4.7.3", + "typescript-to-lua": "^1.9.0" } }, "node_modules/@babel/code-frame": { @@ -952,6 +952,12 @@ "integrity": "sha512-37RSHht+gzzgYeobbG+KWryeAW8J33Nhr69cjTqSYymXVZEN9NbRYWoYlRtDhHKPVT1FyNKwaTPC1NynKZpzRA==", "dev": true }, + "node_modules/@typescript-to-lua/language-extensions": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/@typescript-to-lua/language-extensions/-/language-extensions-1.0.0.tgz", + "integrity": "sha512-GtmhFqyg+txpGgGLM3mlS3R6AEG9MQhKALxxcbr6SBzg9u7YAXcPKqUBaBYd6nH+Pi/eQLcWz4BNOLhz8v4TjQ==", + "dev": true + }, "node_modules/abab": { "version": "2.0.5", "resolved": "https://registry.npmjs.org/abab/-/abab-2.0.5.tgz", @@ -1033,9 +1039,9 @@ } }, "node_modules/ansi-regex": { - "version": "5.0.0", - "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-5.0.0.tgz", - "integrity": "sha512-bY6fj56OUQ0hU1KjFNDQuJFezqKdrAyFdIevADiqrWHwSlbmBNMHp5ak2f40Pm8JTFyM2mqxkG6ngkHO11f/lg==", + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-5.0.1.tgz", + "integrity": "sha512-quJQXlTSUGL2LH9SUXo8VwsY4soanhgo6LNSm84E1LBcE8s3O0wpdiRzyR9z/ZZJMlMWv37qOOb9pdJlMUEKFQ==", "dev": true, "engines": { "node": ">=8" @@ -1933,9 +1939,9 @@ } }, "node_modules/enhanced-resolve": { - "version": "5.8.2", - "resolved": "https://registry.npmjs.org/enhanced-resolve/-/enhanced-resolve-5.8.2.tgz", - "integrity": "sha512-F27oB3WuHDzvR2DOGNTaYy0D5o0cnrv8TeI482VM4kYgQd/FT9lUQwuNsJ0oOHtBUq7eiW5ytqzp7nBFknL+GA==", + "version": "5.10.0", + "resolved": "https://registry.npmjs.org/enhanced-resolve/-/enhanced-resolve-5.10.0.tgz", + "integrity": "sha512-T0yTFjdpldGY8PmuXXR0PyQ1ufZpEGiHVrp7zHKB7jdR4qlmZHhONVM5AQOAWXuF/w3dnHbEQVrNptJgt7F+cQ==", "dev": true, "dependencies": { "graceful-fs": "^4.2.4", @@ -3708,9 +3714,9 @@ "dev": true }, "node_modules/json-schema": { - "version": "0.2.3", - "resolved": "https://registry.npmjs.org/json-schema/-/json-schema-0.2.3.tgz", - "integrity": "sha1-tIDIkuWaLwWVTOcnvT8qTogvnhM=", + "version": "0.4.0", + "resolved": "https://registry.npmjs.org/json-schema/-/json-schema-0.4.0.tgz", + "integrity": "sha512-es94M3nTIfsEPisRafak+HDLfHXnKBhV3vU5eqPcS3flIWqcxJWgXHXiey3YrpaNsanY5ei1VoYEbOzijuq9BA==", "dev": true }, "node_modules/json-schema-traverse": { @@ -3741,18 +3747,18 @@ } }, "node_modules/jsprim": { - "version": "1.4.1", - "resolved": "https://registry.npmjs.org/jsprim/-/jsprim-1.4.1.tgz", - "integrity": "sha1-MT5mvB5cwG5Di8G3SZwuXFastqI=", + "version": "1.4.2", + "resolved": "https://registry.npmjs.org/jsprim/-/jsprim-1.4.2.tgz", + "integrity": "sha512-P2bSOMAc/ciLz6DzgjVlGJP9+BrJWu5UDGK70C2iweC5QBIeFf0ZXRvGjEj2uYgrY2MkAAhsSWHDWlFtEroZWw==", "dev": true, - "engines": [ - "node >=0.6.0" - ], "dependencies": { "assert-plus": "1.0.0", "extsprintf": "1.3.0", - "json-schema": "0.2.3", + "json-schema": "0.4.0", "verror": "1.10.0" + }, + "engines": { + "node": ">=0.6.0" } }, "node_modules/kind-of": { @@ -3950,9 +3956,9 @@ } }, "node_modules/minimist": { - "version": "1.2.5", - "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.5.tgz", - "integrity": "sha512-FM9nNUYrRBAELZQT3xeZQ7fmMOBg6nWNmJKTcgsJeaLstP/UODVpGsr5OhXhhXg6f+qtJ8uiZ+PUxkDWcgIXLw==", + "version": "1.2.6", + "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.6.tgz", + "integrity": "sha512-Jsjnk4bw3YJqYzbdyBiNsPWHPfO++UGG749Cxs6peCu5Xg4nrena6OVxOYxrQTqww0Jmwt+Ref8rggumkTLz9Q==", "dev": true }, "node_modules/mixin-deep": { @@ -5823,9 +5829,9 @@ "dev": true }, "node_modules/tmpl": { - "version": "1.0.4", - "resolved": "https://registry.npmjs.org/tmpl/-/tmpl-1.0.4.tgz", - "integrity": "sha1-I2QN17QtAEM5ERQIIOXPRA5SHdE=", + "version": "1.0.5", + "resolved": "https://registry.npmjs.org/tmpl/-/tmpl-1.0.5.tgz", + "integrity": "sha512-3f0uOEAQwIqGuWW2MVzYg8fV/QNnc/IpuJNG837rLuczAaLVHslWHZQj4IGiEl5Hs3kkbhwL9Ab7Hrsmuj+Smw==", "dev": true }, "node_modules/to-fast-properties": { @@ -6018,9 +6024,9 @@ } }, "node_modules/typescript": { - "version": "4.3.5", - "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.3.5.tgz", - "integrity": "sha512-DqQgihaQ9cUrskJo9kIyW/+g0Vxsk8cDtZ52a3NGh0YNTfpUSArXSohyUGnvbPazEPLu398C0UxmKSOrPumUzA==", + "version": "4.7.3", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.7.3.tgz", + "integrity": "sha512-WOkT3XYvrpXx4vMMqlD+8R8R37fZkjyLGlxavMc4iB8lrl8L0DeTcHbYgw/v0N/z9wAFsgBhcsF0ruoySS22mA==", "dev": true, "bin": { "tsc": "bin/tsc", @@ -6031,22 +6037,23 @@ } }, "node_modules/typescript-to-lua": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/typescript-to-lua/-/typescript-to-lua-1.0.1.tgz", - "integrity": "sha512-j5mb+8HgUUY8hhAKoNy6KUMeamEN1fsTtMvSbPaxmVkWw40pHdLi3umsQG+Qo7wM6IK+RQffFxbIWEjleF+xpw==", + "version": "1.9.0", + "resolved": "https://registry.npmjs.org/typescript-to-lua/-/typescript-to-lua-1.9.0.tgz", + "integrity": "sha512-Oj8kutP1u/TSjN9oGUuESfOL+feHMSs7CCxl90C60jWTH+4ZXLtrXlRJTalA3Z2/aHjQXXgPaXQStSXBzAYLow==", "dev": true, - "license": "MIT", "dependencies": { "enhanced-resolve": "^5.8.2", "resolve": "^1.15.1", - "source-map": "^0.7.3", - "typescript": "~4.3.5" + "source-map": "^0.7.3" }, "bin": { "tstl": "dist/tstl.js" }, "engines": { "node": ">=12.13.0" + }, + "peerDependencies": { + "typescript": "~4.7.3" } }, "node_modules/union-value": { @@ -7239,6 +7246,12 @@ "integrity": "sha512-37RSHht+gzzgYeobbG+KWryeAW8J33Nhr69cjTqSYymXVZEN9NbRYWoYlRtDhHKPVT1FyNKwaTPC1NynKZpzRA==", "dev": true }, + "@typescript-to-lua/language-extensions": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/@typescript-to-lua/language-extensions/-/language-extensions-1.0.0.tgz", + "integrity": "sha512-GtmhFqyg+txpGgGLM3mlS3R6AEG9MQhKALxxcbr6SBzg9u7YAXcPKqUBaBYd6nH+Pi/eQLcWz4BNOLhz8v4TjQ==", + "dev": true + }, "abab": { "version": "2.0.5", "resolved": "https://registry.npmjs.org/abab/-/abab-2.0.5.tgz", @@ -7297,9 +7310,9 @@ } }, "ansi-regex": { - "version": "5.0.0", - "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-5.0.0.tgz", - "integrity": "sha512-bY6fj56OUQ0hU1KjFNDQuJFezqKdrAyFdIevADiqrWHwSlbmBNMHp5ak2f40Pm8JTFyM2mqxkG6ngkHO11f/lg==", + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-5.0.1.tgz", + "integrity": "sha512-quJQXlTSUGL2LH9SUXo8VwsY4soanhgo6LNSm84E1LBcE8s3O0wpdiRzyR9z/ZZJMlMWv37qOOb9pdJlMUEKFQ==", "dev": true }, "ansi-styles": { @@ -8009,9 +8022,9 @@ } }, "enhanced-resolve": { - "version": "5.8.2", - "resolved": "https://registry.npmjs.org/enhanced-resolve/-/enhanced-resolve-5.8.2.tgz", - "integrity": "sha512-F27oB3WuHDzvR2DOGNTaYy0D5o0cnrv8TeI482VM4kYgQd/FT9lUQwuNsJ0oOHtBUq7eiW5ytqzp7nBFknL+GA==", + "version": "5.10.0", + "resolved": "https://registry.npmjs.org/enhanced-resolve/-/enhanced-resolve-5.10.0.tgz", + "integrity": "sha512-T0yTFjdpldGY8PmuXXR0PyQ1ufZpEGiHVrp7zHKB7jdR4qlmZHhONVM5AQOAWXuF/w3dnHbEQVrNptJgt7F+cQ==", "dev": true, "requires": { "graceful-fs": "^4.2.4", @@ -9394,9 +9407,9 @@ "dev": true }, "json-schema": { - "version": "0.2.3", - "resolved": "https://registry.npmjs.org/json-schema/-/json-schema-0.2.3.tgz", - "integrity": "sha1-tIDIkuWaLwWVTOcnvT8qTogvnhM=", + "version": "0.4.0", + "resolved": "https://registry.npmjs.org/json-schema/-/json-schema-0.4.0.tgz", + "integrity": "sha512-es94M3nTIfsEPisRafak+HDLfHXnKBhV3vU5eqPcS3flIWqcxJWgXHXiey3YrpaNsanY5ei1VoYEbOzijuq9BA==", "dev": true }, "json-schema-traverse": { @@ -9421,14 +9434,14 @@ } }, "jsprim": { - "version": "1.4.1", - "resolved": "https://registry.npmjs.org/jsprim/-/jsprim-1.4.1.tgz", - "integrity": "sha1-MT5mvB5cwG5Di8G3SZwuXFastqI=", + "version": "1.4.2", + "resolved": "https://registry.npmjs.org/jsprim/-/jsprim-1.4.2.tgz", + "integrity": "sha512-P2bSOMAc/ciLz6DzgjVlGJP9+BrJWu5UDGK70C2iweC5QBIeFf0ZXRvGjEj2uYgrY2MkAAhsSWHDWlFtEroZWw==", "dev": true, "requires": { "assert-plus": "1.0.0", "extsprintf": "1.3.0", - "json-schema": "0.2.3", + "json-schema": "0.4.0", "verror": "1.10.0" } }, @@ -9582,9 +9595,9 @@ } }, "minimist": { - "version": "1.2.5", - "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.5.tgz", - "integrity": "sha512-FM9nNUYrRBAELZQT3xeZQ7fmMOBg6nWNmJKTcgsJeaLstP/UODVpGsr5OhXhhXg6f+qtJ8uiZ+PUxkDWcgIXLw==", + "version": "1.2.6", + "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.6.tgz", + "integrity": "sha512-Jsjnk4bw3YJqYzbdyBiNsPWHPfO++UGG749Cxs6peCu5Xg4nrena6OVxOYxrQTqww0Jmwt+Ref8rggumkTLz9Q==", "dev": true }, "mixin-deep": { @@ -11062,9 +11075,9 @@ "dev": true }, "tmpl": { - "version": "1.0.4", - "resolved": "https://registry.npmjs.org/tmpl/-/tmpl-1.0.4.tgz", - "integrity": "sha1-I2QN17QtAEM5ERQIIOXPRA5SHdE=", + "version": "1.0.5", + "resolved": "https://registry.npmjs.org/tmpl/-/tmpl-1.0.5.tgz", + "integrity": "sha512-3f0uOEAQwIqGuWW2MVzYg8fV/QNnc/IpuJNG837rLuczAaLVHslWHZQj4IGiEl5Hs3kkbhwL9Ab7Hrsmuj+Smw==", "dev": true }, "to-fast-properties": { @@ -11209,21 +11222,20 @@ } }, "typescript": { - "version": "4.3.5", - "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.3.5.tgz", - "integrity": "sha512-DqQgihaQ9cUrskJo9kIyW/+g0Vxsk8cDtZ52a3NGh0YNTfpUSArXSohyUGnvbPazEPLu398C0UxmKSOrPumUzA==", + "version": "4.7.3", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.7.3.tgz", + "integrity": "sha512-WOkT3XYvrpXx4vMMqlD+8R8R37fZkjyLGlxavMc4iB8lrl8L0DeTcHbYgw/v0N/z9wAFsgBhcsF0ruoySS22mA==", "dev": true }, "typescript-to-lua": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/typescript-to-lua/-/typescript-to-lua-1.0.1.tgz", - "integrity": "sha512-j5mb+8HgUUY8hhAKoNy6KUMeamEN1fsTtMvSbPaxmVkWw40pHdLi3umsQG+Qo7wM6IK+RQffFxbIWEjleF+xpw==", + "version": "1.9.0", + "resolved": "https://registry.npmjs.org/typescript-to-lua/-/typescript-to-lua-1.9.0.tgz", + "integrity": "sha512-Oj8kutP1u/TSjN9oGUuESfOL+feHMSs7CCxl90C60jWTH+4ZXLtrXlRJTalA3Z2/aHjQXXgPaXQStSXBzAYLow==", "dev": true, "requires": { "enhanced-resolve": "^5.8.2", "resolve": "^1.15.1", - "source-map": "^0.7.3", - "typescript": "~4.3.5" + "source-map": "^0.7.3" } }, "union-value": { diff --git a/package.json b/package.json index 2f12c8d..75ef0da 100644 --- a/package.json +++ b/package.json @@ -14,7 +14,8 @@ "**/*.d.ts" ], "scripts": { - "test": "jest", + "test": "jest && npm run test:test-project", + "test:test-project": "npm --prefix test/testproject ci && npm --prefix test/testproject run build", "lint": "prettier --check ." }, "prettier": { @@ -23,9 +24,6 @@ "proseWrap": "never", "singleQuote": true }, - "peerDependencies": { - "typescript-to-lua": "^1.0.0" - }, "devDependencies": { "@types/jest": "^26.0.20", "@types/node": "^14.14.34", @@ -33,6 +31,11 @@ "jest-circus": "^26.6.3", "prettier": "^2.0.5", "ts-jest": "^26.5.3", - "typescript-to-lua": "^1.0.1" + "typescript": "4.7.3", + "typescript-to-lua": "^1.9.0", + "@typescript-to-lua/language-extensions": "^1.0.0" + }, + "peer-dependencies": { + "@typescript-to-lua/language-extensions": "^1.0.0" } } diff --git a/test/__snapshots__/global.spec.ts.snap b/test/__snapshots__/global.spec.ts.snap index a20d2fa..bbfe81b 100644 --- a/test/__snapshots__/global.spec.ts.snap +++ b/test/__snapshots__/global.spec.ts.snap @@ -71,11 +71,7 @@ exports[`Lua version 5.1 / global pcall with context 1`] = ` exports[`Lua version 5.1 / global rawget 1`] = `"value = rawget({foo = \\"bar\\"}, \\"foo\\")"`; -exports[`Lua version 5.1 / global select 1`] = ` -"values = { - select(2, \\"a\\", \\"b\\", \\"c\\") -}" -`; +exports[`Lua version 5.1 / global select 1`] = `"values = {select(2, \\"a\\", \\"b\\", \\"c\\")}"`; exports[`Lua version 5.1 / global select destructured 1`] = `"b, c = select(2, \\"a\\", \\"b\\", \\"c\\")"`; @@ -84,9 +80,7 @@ exports[`Lua version 5.1 / global select with # 1`] = `"count = select(\\"#\\", exports[`Lua version 5.1 / global setmetatable with function index 1`] = ` "tbl = setmetatable( {}, - { - __index = function(____, key) return key .. \\"bar\\" end - } + {__index = function(____, key) return key .. \\"bar\\" end} ) takesStr = function(____, s) end @@ -181,11 +175,7 @@ exports[`Lua version 5.2 / global pcall with context 1`] = ` exports[`Lua version 5.2 / global rawget 1`] = `"value = rawget({foo = \\"bar\\"}, \\"foo\\")"`; -exports[`Lua version 5.2 / global select 1`] = ` -"values = { - select(2, \\"a\\", \\"b\\", \\"c\\") -}" -`; +exports[`Lua version 5.2 / global select 1`] = `"values = {select(2, \\"a\\", \\"b\\", \\"c\\")}"`; exports[`Lua version 5.2 / global select destructured 1`] = `"b, c = select(2, \\"a\\", \\"b\\", \\"c\\")"`; @@ -194,9 +184,7 @@ exports[`Lua version 5.2 / global select with # 1`] = `"count = select(\\"#\\", exports[`Lua version 5.2 / global setmetatable with function index 1`] = ` "tbl = setmetatable( {}, - { - __index = function(____, key) return key .. \\"bar\\" end - } + {__index = function(____, key) return key .. \\"bar\\" end} ) takesStr = function(____, s) end @@ -291,11 +279,7 @@ exports[`Lua version 5.3 / global pcall with context 1`] = ` exports[`Lua version 5.3 / global rawget 1`] = `"value = rawget({foo = \\"bar\\"}, \\"foo\\")"`; -exports[`Lua version 5.3 / global select 1`] = ` -"values = { - select(2, \\"a\\", \\"b\\", \\"c\\") -}" -`; +exports[`Lua version 5.3 / global select 1`] = `"values = {select(2, \\"a\\", \\"b\\", \\"c\\")}"`; exports[`Lua version 5.3 / global select destructured 1`] = `"b, c = select(2, \\"a\\", \\"b\\", \\"c\\")"`; @@ -304,9 +288,7 @@ exports[`Lua version 5.3 / global select with # 1`] = `"count = select(\\"#\\", exports[`Lua version 5.3 / global setmetatable with function index 1`] = ` "tbl = setmetatable( {}, - { - __index = function(____, key) return key .. \\"bar\\" end - } + {__index = function(____, key) return key .. \\"bar\\" end} ) takesStr = function(____, s) end @@ -401,11 +383,7 @@ exports[`Lua version 5.4 / global pcall with context 1`] = ` exports[`Lua version 5.4 / global rawget 1`] = `"value = rawget({foo = \\"bar\\"}, \\"foo\\")"`; -exports[`Lua version 5.4 / global select 1`] = ` -"values = { - select(2, \\"a\\", \\"b\\", \\"c\\") -}" -`; +exports[`Lua version 5.4 / global select 1`] = `"values = {select(2, \\"a\\", \\"b\\", \\"c\\")}"`; exports[`Lua version 5.4 / global select destructured 1`] = `"b, c = select(2, \\"a\\", \\"b\\", \\"c\\")"`; @@ -414,9 +392,7 @@ exports[`Lua version 5.4 / global select with # 1`] = `"count = select(\\"#\\", exports[`Lua version 5.4 / global setmetatable with function index 1`] = ` "tbl = setmetatable( {}, - { - __index = function(____, key) return key .. \\"bar\\" end - } + {__index = function(____, key) return key .. \\"bar\\" end} ) takesStr = function(____, s) end @@ -511,11 +487,7 @@ exports[`Lua version JIT / global pcall with context 1`] = ` exports[`Lua version JIT / global rawget 1`] = `"value = rawget({foo = \\"bar\\"}, \\"foo\\")"`; -exports[`Lua version JIT / global select 1`] = ` -"values = { - select(2, \\"a\\", \\"b\\", \\"c\\") -}" -`; +exports[`Lua version JIT / global select 1`] = `"values = {select(2, \\"a\\", \\"b\\", \\"c\\")}"`; exports[`Lua version JIT / global select destructured 1`] = `"b, c = select(2, \\"a\\", \\"b\\", \\"c\\")"`; @@ -524,9 +496,7 @@ exports[`Lua version JIT / global select with # 1`] = `"count = select(\\"#\\", exports[`Lua version JIT / global setmetatable with function index 1`] = ` "tbl = setmetatable( {}, - { - __index = function(____, key) return key .. \\"bar\\" end - } + {__index = function(____, key) return key .. \\"bar\\" end} ) takesStr = function(____, s) end diff --git a/test/__snapshots__/io.spec.ts.snap b/test/__snapshots__/io.spec.ts.snap index e44aaf4..7d8f79b 100644 --- a/test/__snapshots__/io.spec.ts.snap +++ b/test/__snapshots__/io.spec.ts.snap @@ -98,11 +98,7 @@ exports[`Lua version 5.1 / io stdout 1`] = `"io.stdout:write(\\"foobar\\")"`; exports[`Lua version 5.1 / io tmpfile 1`] = `"file = io.tmpfile()"`; -exports[`Lua version 5.1 / io type 1`] = ` -"print( - io.type(file) -)" -`; +exports[`Lua version 5.1 / io type 1`] = `"print(io.type(file))"`; exports[`Lua version 5.1 / io write 1`] = `"f, err = io.write(\\"foobar\\")"`; @@ -204,11 +200,7 @@ exports[`Lua version 5.2 / io stdout 1`] = `"io.stdout:write(\\"foobar\\")"`; exports[`Lua version 5.2 / io tmpfile 1`] = `"file = io.tmpfile()"`; -exports[`Lua version 5.2 / io type 1`] = ` -"print( - io.type(file) -)" -`; +exports[`Lua version 5.2 / io type 1`] = `"print(io.type(file))"`; exports[`Lua version 5.2 / io write 1`] = `"f, err = io.write(\\"foobar\\")"`; @@ -310,11 +302,7 @@ exports[`Lua version 5.3 / io stdout 1`] = `"io.stdout:write(\\"foobar\\")"`; exports[`Lua version 5.3 / io tmpfile 1`] = `"file = io.tmpfile()"`; -exports[`Lua version 5.3 / io type 1`] = ` -"print( - io.type(file) -)" -`; +exports[`Lua version 5.3 / io type 1`] = `"print(io.type(file))"`; exports[`Lua version 5.3 / io write 1`] = `"f, err = io.write(\\"foobar\\")"`; @@ -416,11 +404,7 @@ exports[`Lua version 5.4 / io stdout 1`] = `"io.stdout:write(\\"foobar\\")"`; exports[`Lua version 5.4 / io tmpfile 1`] = `"file = io.tmpfile()"`; -exports[`Lua version 5.4 / io type 1`] = ` -"print( - io.type(file) -)" -`; +exports[`Lua version 5.4 / io type 1`] = `"print(io.type(file))"`; exports[`Lua version 5.4 / io write 1`] = `"f, err = io.write(\\"foobar\\")"`; @@ -522,10 +506,6 @@ exports[`Lua version JIT / io stdout 1`] = `"io.stdout:write(\\"foobar\\")"`; exports[`Lua version JIT / io tmpfile 1`] = `"file = io.tmpfile()"`; -exports[`Lua version JIT / io type 1`] = ` -"print( - io.type(file) -)" -`; +exports[`Lua version JIT / io type 1`] = `"print(io.type(file))"`; exports[`Lua version JIT / io write 1`] = `"f, err = io.write(\\"foobar\\")"`; diff --git a/test/__snapshots__/string.spec.ts.snap b/test/__snapshots__/string.spec.ts.snap index 38517fc..0bc6d11 100644 --- a/test/__snapshots__/string.spec.ts.snap +++ b/test/__snapshots__/string.spec.ts.snap @@ -6,17 +6,9 @@ exports[`Lua version 5.1 / string string.byte multiple 1`] = `"a, b, c, d = stri exports[`Lua version 5.1 / string string.char 1`] = `"str = string.char(64, 65, 66)"`; -exports[`Lua version 5.1 / string string.dump 1`] = ` -"str = string.dump( - function() return 5 end -)" -`; +exports[`Lua version 5.1 / string string.dump 1`] = `"str = string.dump(function() return 5 end)"`; -exports[`Lua version 5.1 / string string.find 1`] = ` -"result = { - string.find(\\"abc\\", \\"b\\") -}" -`; +exports[`Lua version 5.1 / string string.find 1`] = `"result = {string.find(\\"abc\\", \\"b\\")}"`; exports[`Lua version 5.1 / string string.find destructure 1`] = `"start, ____end, matchString = string.find(\\"abc\\", \\"b\\")"`; @@ -39,34 +31,20 @@ end" `; exports[`Lua version 5.1 / string string.gsub function 1`] = ` -"result = { - string.gsub( - \\"hello world\\", - \\"l\\", - function(match) return \\"R\\" end - ) -}" +"result = {string.gsub( + \\"hello world\\", + \\"l\\", + function(match) return \\"R\\" end +)}" `; -exports[`Lua version 5.1 / string string.gsub string 1`] = ` -"result = { - string.gsub(\\"hello world\\", \\"l\\", \\"R\\") -}" -`; +exports[`Lua version 5.1 / string string.gsub string 1`] = `"result = {string.gsub(\\"hello world\\", \\"l\\", \\"R\\")}"`; exports[`Lua version 5.1 / string string.gsub string destructured 1`] = `"result, numOccurrences = string.gsub(\\"hello world\\", \\"l\\", \\"R\\")"`; -exports[`Lua version 5.1 / string string.gsub table 1`] = ` -"result = { - string.gsub(\\"hello world\\", \\"l\\", {l = \\"R\\"}) -}" -`; +exports[`Lua version 5.1 / string string.gsub table 1`] = `"result = {string.gsub(\\"hello world\\", \\"l\\", {l = \\"R\\"})}"`; -exports[`Lua version 5.1 / string string.match 1`] = ` -"result = { - string.match(\\"hello world\\", \\"l\\") -}" -`; +exports[`Lua version 5.1 / string string.match 1`] = `"result = {string.match(\\"hello world\\", \\"l\\")}"`; exports[`Lua version 5.1 / string string.match destructured 1`] = `"match1, match2 = string.match(\\"hello world\\", \\"l\\")"`; @@ -78,17 +56,9 @@ exports[`Lua version 5.2 / string string.byte multiple 1`] = `"a, b, c, d = stri exports[`Lua version 5.2 / string string.char 1`] = `"str = string.char(64, 65, 66)"`; -exports[`Lua version 5.2 / string string.dump 1`] = ` -"str = string.dump( - function() return 5 end -)" -`; +exports[`Lua version 5.2 / string string.dump 1`] = `"str = string.dump(function() return 5 end)"`; -exports[`Lua version 5.2 / string string.find 1`] = ` -"result = { - string.find(\\"abc\\", \\"b\\") -}" -`; +exports[`Lua version 5.2 / string string.find 1`] = `"result = {string.find(\\"abc\\", \\"b\\")}"`; exports[`Lua version 5.2 / string string.find destructure 1`] = `"start, ____end, matchString = string.find(\\"abc\\", \\"b\\")"`; @@ -111,34 +81,20 @@ end" `; exports[`Lua version 5.2 / string string.gsub function 1`] = ` -"result = { - string.gsub( - \\"hello world\\", - \\"l\\", - function(match) return \\"R\\" end - ) -}" +"result = {string.gsub( + \\"hello world\\", + \\"l\\", + function(match) return \\"R\\" end +)}" `; -exports[`Lua version 5.2 / string string.gsub string 1`] = ` -"result = { - string.gsub(\\"hello world\\", \\"l\\", \\"R\\") -}" -`; +exports[`Lua version 5.2 / string string.gsub string 1`] = `"result = {string.gsub(\\"hello world\\", \\"l\\", \\"R\\")}"`; exports[`Lua version 5.2 / string string.gsub string destructured 1`] = `"result, numOccurrences = string.gsub(\\"hello world\\", \\"l\\", \\"R\\")"`; -exports[`Lua version 5.2 / string string.gsub table 1`] = ` -"result = { - string.gsub(\\"hello world\\", \\"l\\", {l = \\"R\\"}) -}" -`; +exports[`Lua version 5.2 / string string.gsub table 1`] = `"result = {string.gsub(\\"hello world\\", \\"l\\", {l = \\"R\\"})}"`; -exports[`Lua version 5.2 / string string.match 1`] = ` -"result = { - string.match(\\"hello world\\", \\"l\\") -}" -`; +exports[`Lua version 5.2 / string string.match 1`] = `"result = {string.match(\\"hello world\\", \\"l\\")}"`; exports[`Lua version 5.2 / string string.match destructured 1`] = `"match1, match2 = string.match(\\"hello world\\", \\"l\\")"`; @@ -150,17 +106,9 @@ exports[`Lua version 5.3 / string string.byte multiple 1`] = `"a, b, c, d = stri exports[`Lua version 5.3 / string string.char 1`] = `"str = string.char(64, 65, 66)"`; -exports[`Lua version 5.3 / string string.dump 1`] = ` -"str = string.dump( - function() return 5 end -)" -`; +exports[`Lua version 5.3 / string string.dump 1`] = `"str = string.dump(function() return 5 end)"`; -exports[`Lua version 5.3 / string string.find 1`] = ` -"result = { - string.find(\\"abc\\", \\"b\\") -}" -`; +exports[`Lua version 5.3 / string string.find 1`] = `"result = {string.find(\\"abc\\", \\"b\\")}"`; exports[`Lua version 5.3 / string string.find destructure 1`] = `"start, ____end, matchString = string.find(\\"abc\\", \\"b\\")"`; @@ -183,34 +131,20 @@ end" `; exports[`Lua version 5.3 / string string.gsub function 1`] = ` -"result = { - string.gsub( - \\"hello world\\", - \\"l\\", - function(match) return \\"R\\" end - ) -}" +"result = {string.gsub( + \\"hello world\\", + \\"l\\", + function(match) return \\"R\\" end +)}" `; -exports[`Lua version 5.3 / string string.gsub string 1`] = ` -"result = { - string.gsub(\\"hello world\\", \\"l\\", \\"R\\") -}" -`; +exports[`Lua version 5.3 / string string.gsub string 1`] = `"result = {string.gsub(\\"hello world\\", \\"l\\", \\"R\\")}"`; exports[`Lua version 5.3 / string string.gsub string destructured 1`] = `"result, numOccurrences = string.gsub(\\"hello world\\", \\"l\\", \\"R\\")"`; -exports[`Lua version 5.3 / string string.gsub table 1`] = ` -"result = { - string.gsub(\\"hello world\\", \\"l\\", {l = \\"R\\"}) -}" -`; +exports[`Lua version 5.3 / string string.gsub table 1`] = `"result = {string.gsub(\\"hello world\\", \\"l\\", {l = \\"R\\"})}"`; -exports[`Lua version 5.3 / string string.match 1`] = ` -"result = { - string.match(\\"hello world\\", \\"l\\") -}" -`; +exports[`Lua version 5.3 / string string.match 1`] = `"result = {string.match(\\"hello world\\", \\"l\\")}"`; exports[`Lua version 5.3 / string string.match destructured 1`] = `"match1, match2 = string.match(\\"hello world\\", \\"l\\")"`; @@ -222,17 +156,9 @@ exports[`Lua version 5.4 / string string.byte multiple 1`] = `"a, b, c, d = stri exports[`Lua version 5.4 / string string.char 1`] = `"str = string.char(64, 65, 66)"`; -exports[`Lua version 5.4 / string string.dump 1`] = ` -"str = string.dump( - function() return 5 end -)" -`; +exports[`Lua version 5.4 / string string.dump 1`] = `"str = string.dump(function() return 5 end)"`; -exports[`Lua version 5.4 / string string.find 1`] = ` -"result = { - string.find(\\"abc\\", \\"b\\") -}" -`; +exports[`Lua version 5.4 / string string.find 1`] = `"result = {string.find(\\"abc\\", \\"b\\")}"`; exports[`Lua version 5.4 / string string.find destructure 1`] = `"start, ____end, matchString = string.find(\\"abc\\", \\"b\\")"`; @@ -255,34 +181,20 @@ end" `; exports[`Lua version 5.4 / string string.gsub function 1`] = ` -"result = { - string.gsub( - \\"hello world\\", - \\"l\\", - function(match) return \\"R\\" end - ) -}" +"result = {string.gsub( + \\"hello world\\", + \\"l\\", + function(match) return \\"R\\" end +)}" `; -exports[`Lua version 5.4 / string string.gsub string 1`] = ` -"result = { - string.gsub(\\"hello world\\", \\"l\\", \\"R\\") -}" -`; +exports[`Lua version 5.4 / string string.gsub string 1`] = `"result = {string.gsub(\\"hello world\\", \\"l\\", \\"R\\")}"`; exports[`Lua version 5.4 / string string.gsub string destructured 1`] = `"result, numOccurrences = string.gsub(\\"hello world\\", \\"l\\", \\"R\\")"`; -exports[`Lua version 5.4 / string string.gsub table 1`] = ` -"result = { - string.gsub(\\"hello world\\", \\"l\\", {l = \\"R\\"}) -}" -`; +exports[`Lua version 5.4 / string string.gsub table 1`] = `"result = {string.gsub(\\"hello world\\", \\"l\\", {l = \\"R\\"})}"`; -exports[`Lua version 5.4 / string string.match 1`] = ` -"result = { - string.match(\\"hello world\\", \\"l\\") -}" -`; +exports[`Lua version 5.4 / string string.match 1`] = `"result = {string.match(\\"hello world\\", \\"l\\")}"`; exports[`Lua version 5.4 / string string.match destructured 1`] = `"match1, match2 = string.match(\\"hello world\\", \\"l\\")"`; @@ -294,17 +206,9 @@ exports[`Lua version JIT / string string.byte multiple 1`] = `"a, b, c, d = stri exports[`Lua version JIT / string string.char 1`] = `"str = string.char(64, 65, 66)"`; -exports[`Lua version JIT / string string.dump 1`] = ` -"str = string.dump( - function() return 5 end -)" -`; +exports[`Lua version JIT / string string.dump 1`] = `"str = string.dump(function() return 5 end)"`; -exports[`Lua version JIT / string string.find 1`] = ` -"result = { - string.find(\\"abc\\", \\"b\\") -}" -`; +exports[`Lua version JIT / string string.find 1`] = `"result = {string.find(\\"abc\\", \\"b\\")}"`; exports[`Lua version JIT / string string.find destructure 1`] = `"start, ____end, matchString = string.find(\\"abc\\", \\"b\\")"`; @@ -327,34 +231,20 @@ end" `; exports[`Lua version JIT / string string.gsub function 1`] = ` -"result = { - string.gsub( - \\"hello world\\", - \\"l\\", - function(match) return \\"R\\" end - ) -}" +"result = {string.gsub( + \\"hello world\\", + \\"l\\", + function(match) return \\"R\\" end +)}" `; -exports[`Lua version JIT / string string.gsub string 1`] = ` -"result = { - string.gsub(\\"hello world\\", \\"l\\", \\"R\\") -}" -`; +exports[`Lua version JIT / string string.gsub string 1`] = `"result = {string.gsub(\\"hello world\\", \\"l\\", \\"R\\")}"`; exports[`Lua version JIT / string string.gsub string destructured 1`] = `"result, numOccurrences = string.gsub(\\"hello world\\", \\"l\\", \\"R\\")"`; -exports[`Lua version JIT / string string.gsub table 1`] = ` -"result = { - string.gsub(\\"hello world\\", \\"l\\", {l = \\"R\\"}) -}" -`; +exports[`Lua version JIT / string string.gsub table 1`] = `"result = {string.gsub(\\"hello world\\", \\"l\\", {l = \\"R\\"})}"`; -exports[`Lua version JIT / string string.match 1`] = ` -"result = { - string.match(\\"hello world\\", \\"l\\") -}" -`; +exports[`Lua version JIT / string string.match 1`] = `"result = {string.match(\\"hello world\\", \\"l\\")}"`; exports[`Lua version JIT / string string.match destructured 1`] = `"match1, match2 = string.match(\\"hello world\\", \\"l\\")"`; diff --git a/test/test-utils.ts b/test/test-utils.ts index c8b0437..cce9a3b 100644 --- a/test/test-utils.ts +++ b/test/test-utils.ts @@ -2,7 +2,7 @@ import * as fs from 'fs'; import * as path from 'path'; import * as ts from 'typescript'; -import { LuaTarget, Transpiler } from 'typescript-to-lua'; +import { LuaTarget, Transpiler, CompilerOptions } from 'typescript-to-lua'; const targets = [ LuaTarget.Lua51, @@ -25,7 +25,7 @@ export function tstl(luaTarget: LuaTarget, input: string): string { // Create a TS program containing input.ts and the declarations file to test const rootNames = ['input.ts', typesPath]; - const options = { + const options: CompilerOptions = { luaTarget, lib: ['lib.esnext.d.ts'], noHeader: true, @@ -83,21 +83,28 @@ function getCompilerHostWithInput(input: string) { let filePath = fileName; - if (fileName.startsWith('lib.')) { + if (fileName.includes('/@typescript/')) { const typeScriptDir = path.dirname(require.resolve('typescript')); - filePath = path.join(typeScriptDir, fileName); + const pathParts = fileName.split('@typescript/')[1].split('/'); + let libFileName = pathParts.join('.').replace(/-/g, '.'); + if (libFileName.endsWith('.ts') && !libFileName.endsWith('.d.ts')) { + libFileName = libFileName.substring(0, libFileName.length - 3) + '.d.ts'; + } + filePath = path.join(typeScriptDir, libFileName); } - if (fileName.endsWith('typescript-to-lua/language-extensions/index.d.ts')) { + if (fileName.endsWith('@typescript-to-lua/language-extensions/index.d.ts')) { filePath = path.resolve( __dirname, - `../node_modules/typescript-to-lua/language-extensions/index.d.ts` + `../node_modules/@typescript-to-lua/language-extensions/index.d.ts` ); } - const fileContent = fs.readFileSync(filePath).toString(); - fileCache[fileName] = fileContent; - return ts.createSourceFile(fileName, fileContent, languageVersion); + if (fs.existsSync(filePath)) { + const fileContent = fs.readFileSync(filePath).toString(); + fileCache[fileName] = fileContent; + return ts.createSourceFile(fileName, fileContent, languageVersion); + } }, }; } diff --git a/test/testproject/main.ts b/test/testproject/main.ts index 206d7fb..5d0d4f0 100644 --- a/test/testproject/main.ts +++ b/test/testproject/main.ts @@ -3,3 +3,7 @@ const mytable = new LuaMap(); for (const [k, v] of pairs(mytable)) { } + +function multiReturn(): LuaMultiReturn<[string, number, string]> { + return $multi('3', 5, '6'); +} diff --git a/test/testproject/package-lock.json b/test/testproject/package-lock.json index 8515a47..1473fbd 100644 --- a/test/testproject/package-lock.json +++ b/test/testproject/package-lock.json @@ -5,7 +5,23 @@ "packages": { "": { "devDependencies": { - "typescript": "^4.8.2", + "lua-types": "file:../..", + "typescript": "~4.7.3", + "typescript-to-lua": "^1.9.0" + } + }, + "../..": { + "version": "2.12.2", + "dev": true, + "license": "MIT", + "devDependencies": { + "@types/jest": "^26.0.20", + "@types/node": "^14.14.34", + "@typescript-to-lua/language-extensions": "^1.0.0", + "jest": "^26.6.3", + "jest-circus": "^26.6.3", + "prettier": "^2.0.5", + "ts-jest": "^26.5.3", "typescript-to-lua": "^1.9.0" } }, @@ -58,6 +74,10 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/lua-types": { + "resolved": "../..", + "link": true + }, "node_modules/path-parse": { "version": "1.0.7", "resolved": "https://registry.npmjs.org/path-parse/-/path-parse-1.0.7.tgz", @@ -112,9 +132,9 @@ } }, "node_modules/typescript": { - "version": "4.8.2", - "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.8.2.tgz", - "integrity": "sha512-C0I1UsrrDHo2fYI5oaCGbSejwX4ch+9Y5jTQELvovfmFkK3HHSZJB8MSJcWLmCUBzQBchCrZ9rMRV6GuNrvGtw==", + "version": "4.7.4", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.7.4.tgz", + "integrity": "sha512-C0WQT0gezHuw6AdY1M2jxUO83Rjf0HP7Sk1DtXj6j1EwkQNZrHAg2XPWlq62oqEhYvONq5pkC2Y9oPljWToLmQ==", "dev": true, "bin": { "tsc": "bin/tsc", @@ -186,6 +206,19 @@ "has": "^1.0.3" } }, + "lua-types": { + "version": "file:../..", + "requires": { + "@types/jest": "^26.0.20", + "@types/node": "^14.14.34", + "@typescript-to-lua/language-extensions": "^1.0.0", + "jest": "^26.6.3", + "jest-circus": "^26.6.3", + "prettier": "^2.0.5", + "ts-jest": "^26.5.3", + "typescript-to-lua": "^1.9.0" + } + }, "path-parse": { "version": "1.0.7", "resolved": "https://registry.npmjs.org/path-parse/-/path-parse-1.0.7.tgz", @@ -222,9 +255,9 @@ "dev": true }, "typescript": { - "version": "4.8.2", - "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.8.2.tgz", - "integrity": "sha512-C0I1UsrrDHo2fYI5oaCGbSejwX4ch+9Y5jTQELvovfmFkK3HHSZJB8MSJcWLmCUBzQBchCrZ9rMRV6GuNrvGtw==", + "version": "4.7.4", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.7.4.tgz", + "integrity": "sha512-C0WQT0gezHuw6AdY1M2jxUO83Rjf0HP7Sk1DtXj6j1EwkQNZrHAg2XPWlq62oqEhYvONq5pkC2Y9oPljWToLmQ==", "dev": true }, "typescript-to-lua": { diff --git a/test/testproject/package.json b/test/testproject/package.json index ac28cc1..3df63a5 100644 --- a/test/testproject/package.json +++ b/test/testproject/package.json @@ -1,6 +1,10 @@ { + "scripts": { + "build": "tstl" + }, "devDependencies": { - "typescript": "~4.8.2", - "typescript-to-lua": "~1.9.0" + "lua-types": "file:../..", + "typescript": "~4.7.3", + "typescript-to-lua": "^1.9.0" } } diff --git a/test/testproject/tsconfig.json b/test/testproject/tsconfig.json index b24a6d2..406f546 100644 --- a/test/testproject/tsconfig.json +++ b/test/testproject/tsconfig.json @@ -2,6 +2,6 @@ "compilerOptions": { "strict": true, "target": "esnext", - "types": ["typescript-to-lua/language-extensions"] + "types": ["@typescript-to-lua/language-extensions"] } }