-
-
Notifications
You must be signed in to change notification settings - Fork 185
Initial Transformer Setup #279
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| Language: JavaScript | ||
| BasedOnStyle: Google | ||
| IndentWidth: 4 | ||
| JavaScriptQuotes: Double | ||
| ColumnLimit: 120 | ||
| AlignAfterOpenBracket: Align | ||
| AllowAllParametersOfDeclarationOnNextLine: false | ||
| BinPackParameters: false | ||
| BinPackArguments: false | ||
| ExperimentalAutoDetectBinPacking: false |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,7 +4,7 @@ coverage: | |
| status: | ||
| project: | ||
| default: | ||
| target: 90 | ||
| target: 80 | ||
| threshold: null | ||
| base: auto | ||
| changes: off | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,6 +2,8 @@ | |
| node_modules/ | ||
| yarn.lock | ||
|
|
||
| .vscode/ | ||
|
|
||
| coverage/ | ||
| .nyc* | ||
| *.js.map | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| import * as ts from "typescript"; | ||
|
|
||
| export class TransformHelper { | ||
| // Helper to create simple lua variable statement; | ||
| public static createLuaVariableStatement( | ||
| identifier: ts.Identifier, | ||
| expression: ts.Expression, | ||
| typeNode?: ts.TypeNode | ||
| ): ts.VariableStatement { | ||
| const declaration = ts.createVariableDeclaration(identifier, typeNode, expression); | ||
| const statement = ts.createVariableStatement([], ts.createVariableDeclarationList([declaration])); | ||
| return statement; | ||
| } | ||
|
|
||
| public static createLuaImport(identifier: ts.Identifier, moduleSpecifier: ts.StringLiteral): ts.VariableStatement { | ||
| const requireIdentifier = ts.createIdentifier("require"); | ||
| const requireCall = | ||
| ts.createCall(requireIdentifier, [ts.createLiteralTypeNode(moduleSpecifier)], [moduleSpecifier]); | ||
| return this.createLuaVariableStatement(identifier, requireCall); | ||
| } | ||
| } |
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1 @@ | ||
| local Test = require("test") | ||
| local Test = require("test"); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,2 @@ | ||
| local test0 = require("test") | ||
| local TestClass = test0.TestClass | ||
| local test = require("test"); | ||
| local TestClass = test.TestClass; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,2 @@ | ||
| local test0 = require("test") | ||
| local RenamedClass = test0.TestClass | ||
| local test = require("test"); | ||
| local RenamedClass = test.TestClass; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -41,20 +41,6 @@ export class LuaModuleTests { | |
| Expect(lua).toBe(`require("lualib_bundle")`); | ||
| } | ||
|
|
||
| @Test("Import named bindings exception") | ||
| public namedBindigsException(): void { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe ignore this for now instead of removing, since we probably want to still have this test on the transformer instead of transpiler.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This test was using a custom created AST/Node I don't think that named bindings exception can ever be thrown. |
||
| const transpiler = util.makeTestTranspiler(); | ||
|
|
||
| const mockDeclaration: any = { | ||
| importClause: {namedBindings: {}}, | ||
| kind: ts.SyntaxKind.ImportDeclaration, | ||
| moduleSpecifier: ts.createLiteral("test"), | ||
| }; | ||
|
|
||
| Expect(() => transpiler.transpileImport(mockDeclaration as ts.ImportDeclaration)) | ||
| .toThrowError(Error, "Unsupported import type."); | ||
| } | ||
|
|
||
| @Test("Non-exported module") | ||
| public nonExportedModule(): void { | ||
| const lua = util.transpileString("module g { export function test() { return 3; } } return g.test();"); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
MonkaS