Skip to content

Commit 1522c6d

Browse files
authored
Merge pull request #105 from Perryvw/feature/undefined-and-test-improvements
Feature/undefined and test improvements
2 parents 341d65b + 40ee16c commit 1522c6d

15 files changed

+228
-120
lines changed

src/CommandLineParser.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ function runDiagnostics(commandLine: ts.ParsedCommandLine) {
136136
}
137137
}
138138

139-
commandLine.errors.forEach((err) => {
139+
commandLine.errors.forEach(err => {
140140
let ignore = false;
141141
// Ignore errors caused by tstl specific compiler options
142142
if (err.code === tsInvalidCompilerOptionErrorCode) {

src/Compiler.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ export function compile(fileNames: string[], options: CompilerOptions): void {
1313
const checker = program.getTypeChecker();
1414

1515
// Get all diagnostics, ignore unsupported extension
16-
const diagnostics = ts.getPreEmitDiagnostics(program).filter((diag) => diag.code !== 6054);
17-
diagnostics.forEach((diagnostic) => {
16+
const diagnostics = ts.getPreEmitDiagnostics(program).filter(diag => diag.code !== 6054);
17+
diagnostics.forEach(diagnostic => {
1818
if (diagnostic.file) {
1919
const { line, character } =
2020
diagnostic.file.getLineAndCharacterOfPosition(diagnostic.start!);
@@ -30,12 +30,12 @@ export function compile(fileNames: string[], options: CompilerOptions): void {
3030
});
3131

3232
// If there are errors dont emit
33-
if (diagnostics.filter((diag) => diag.category === ts.DiagnosticCategory.Error).length > 0) {
33+
if (diagnostics.filter(diag => diag.category === ts.DiagnosticCategory.Error).length > 0) {
3434
console.log("Stopping compilation process because of errors.");
3535
process.exit(1);
3636
}
3737

38-
program.getSourceFiles().forEach((sourceFile) => {
38+
program.getSourceFiles().forEach(sourceFile => {
3939
if (!sourceFile.isDeclarationFile) {
4040
try {
4141
const rootDir = options.rootDir;

src/TSHelper.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,14 @@ export class TSHelper {
2424
}
2525

2626
public static containsStatement(statements: ts.NodeArray<ts.Statement>, kind: ts.SyntaxKind): boolean {
27-
return statements.some((statement) => statement.kind === kind);
27+
return statements.some(statement => statement.kind === kind);
2828
}
2929

3030
public static isFileModule(sourceFile: ts.SourceFile) {
3131
if (sourceFile) {
3232
// Vanilla ts flags files as external module if they have an import or
3333
// export statement, we only check for export statements
34-
return sourceFile.statements.some((statement) =>
34+
return sourceFile.statements.some(statement =>
3535
(ts.getCombinedModifierFlags(statement) & ts.ModifierFlags.Export) !== 0
3636
|| statement.kind === ts.SyntaxKind.ExportAssignment
3737
|| statement.kind === ts.SyntaxKind.ExportDeclaration);
@@ -88,9 +88,11 @@ export class TSHelper {
8888

8989
public static hasCustomDecorator(type: ts.Type, checker: ts.TypeChecker, decorator: string): boolean {
9090
if (type.symbol) {
91-
const comment = type.symbol.getDocumentationComment(checker);
91+
const comments = type.symbol.getDocumentationComment(checker);
9292
const decorators =
93-
comment.filter((_) => _.kind === "text").map((_) => _.text.trim()).filter((_) => _[0] === "!");
93+
comments.filter(comment => comment.kind === "text")
94+
.map(comment => comment.text.trim())
95+
.filter(comment => comment[0] === "!");
9496
return decorators.indexOf(decorator) > -1;
9597
}
9698
return false;

src/Transpiler.ts

Lines changed: 75 additions & 66 deletions
Large diffs are not rendered by default.
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
Test = Test or {}
2+
Test.__index = Test
3+
function Test.new(construct, ...)
4+
local instance = setmetatable({}, Test)
5+
if construct and Test.constructor then Test.constructor(instance, ...) end
6+
return instance
7+
end
8+
function Test.constructor(self,field)
9+
self.field = field
10+
end
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
val1=0
22
val2=2
3-
val3=3
3+
val3=3
4+
local a = val1
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
function myFunc()
2+
return
3+
end
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
class Test {
2+
constructor(private field: number) {}
3+
}

test/translation/ts/enumMembersOnly.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,6 @@ enum TestEnum {
33
val1 = 0,
44
val2 = 2,
55
val3
6-
}
6+
}
7+
8+
const a = TestEnum.val1;
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
function myFunc() {
2+
return;
3+
}

0 commit comments

Comments
 (0)