Skip to content

TypeScriptToLua plugin that transforms all exported variables to global declarations

License

Notifications You must be signed in to change notification settings

thinknathan/tstl-export-to-global

Repository files navigation

tstl-export-to-global

CI GitHub License

TypeScriptToLua plugin that transforms all exported variables in a given file to global declarations.

Can be used as an alternative to tstl-export-as-global. The benefits from switching to this plugin are as follows:

  1. Saves allocating one table
  2. Allows you to use export const FOO = function() instead of export function FOO() if you prefer that syntax
  3. All variables are transformed, not just functions

❗ Use this and any code transformation plugin with caution. Mistakes are possible.

Example

local ____exports = {}
____exports.foo = 10
____exports.bar = function(self)
	...
end
return ____exports

Becomes:

foo = 10
function bar(self)
	...
end

Installation

Requires TSTL >= 1.22.0.

  1. Install this plugin
yarn add tstl-export-to-global -D
# or
npm install tstl-export-to-global --save-dev
  1. Add tstl-export-to-global to tstl.luaPlugins in tsconfig.json

  2. Define match, which will only apply the transformation to files if their input (TypeScript file) path matches.

{
	"tstl": {
		"luaPlugins": [
+			{
+				"name": "tstl-export-to-global",
+				"match": ".*\\..*script.ts$"
+			}
		],
	}
}

License

CC0