Skip to content

Commit be9bb93

Browse files
committed
Merge remote-tracking branch 'upstream/master' into diagnostics
2 parents ac40ce2 + 50817f8 commit be9bb93

File tree

26 files changed

+245
-426
lines changed

26 files changed

+245
-426
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ The real power of this transpiler is usage together with good declarations for t
6363
- [Dota 2 Modding](https://github.com/ModDota/API/tree/master/declarations/server)
6464
- [Defold Game Engine Scripting](https://github.com/dasannikov/DefoldTypeScript/blob/master/defold.d.ts)
6565
- [LÖVE 2D Game Development](https://github.com/hazzard993/love-typescript-definitions)
66+
- [World of Warcraft - Addon Development](https://github.com/wartoshika/wow-declarations)
67+
- [World of Warcraft Classic - Addon Development](https://github.com/wartoshika/wow-classic-declarations)
6668

6769
## Sublime Text integration
6870

src/CompilerOptions.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ export type CompilerOptions = OmitIndexSignature<ts.CompilerOptions> & {
2424
luaBundleEntry?: string;
2525
luaTarget?: LuaTarget;
2626
luaLibImport?: LuaLibImportKind;
27-
noHoisting?: boolean;
2827
sourceMapTraceback?: boolean;
2928
plugins?: Array<ts.PluginImport | TransformerImport>;
3029
[option: string]: ts.CompilerOptions[string] | Array<ts.PluginImport | TransformerImport>;

src/LuaLib.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ export enum LuaLibFeature {
7373
const luaLibDependencies: { [lib in LuaLibFeature]?: LuaLibFeature[] } = {
7474
ArrayFlat: [LuaLibFeature.ArrayConcat],
7575
ArrayFlatMap: [LuaLibFeature.ArrayConcat],
76-
Error: [LuaLibFeature.New, LuaLibFeature.FunctionCall],
76+
Error: [LuaLibFeature.New, LuaLibFeature.Class, LuaLibFeature.FunctionCall],
7777
InstanceOf: [LuaLibFeature.Symbol],
7878
Iterator: [LuaLibFeature.Symbol],
7979
ObjectFromEntries: [LuaLibFeature.Iterator, LuaLibFeature.Symbol],

src/cli/parse.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,6 @@ export const optionDeclarations: CommandLineOption[] = [
6161
description: "Specify if a header will be added to compiled files.",
6262
type: "boolean",
6363
},
64-
{
65-
name: "noHoisting",
66-
description: "Disables hoisting.",
67-
type: "boolean",
68-
},
6964
{
7065
name: "sourceMapTraceback",
7166
description: "Applies the source map to show source TS files and lines in error tracebacks.",

src/transformation/utils/diagnostics.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -129,12 +129,6 @@ export const invalidAmbientIdentifierName = createDiagnosticFactory(
129129
(text: string) => `Invalid ambient identifier name '${text}'. Ambient identifiers must be valid lua identifiers.`
130130
);
131131

132-
export const referencedBeforeDeclaration = createDiagnosticFactory(
133-
(text: string) =>
134-
`Identifier '${text}' was referenced before it was declared. The declaration ` +
135-
"must be moved before the identifier's use, or hoisting must be enabled."
136-
);
137-
138132
export const unresolvableRequirePath = createDiagnosticFactory(
139133
(path: string) => `Cannot create require path. Module '${path}' does not exist within --rootDir.`
140134
);

src/transformation/utils/lua-ast.ts

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ export function createHoistableVariableDeclarationStatement(
9595
tsOriginal?: ts.Node
9696
): lua.AssignmentStatement | lua.VariableDeclarationStatement {
9797
const declaration = lua.createVariableDeclarationStatement(identifier, initializer, tsOriginal);
98-
if (!context.options.noHoisting && identifier.symbolId) {
98+
if (identifier.symbolId !== undefined) {
9999
const scope = peekScope(context);
100100
assert(scope.type !== ScopeType.Switch);
101101

@@ -158,17 +158,15 @@ export function createLocalOrExportedOrGlobalDeclaration(
158158
declaration = lua.createVariableDeclarationStatement(lhs, rhs, tsOriginal);
159159
}
160160

161-
if (!context.options.noHoisting) {
162-
// Remember local variable declarations for hoisting later
163-
if (!scope.variableDeclarations) {
164-
scope.variableDeclarations = [];
165-
}
161+
// Remember local variable declarations for hoisting later
162+
if (!scope.variableDeclarations) {
163+
scope.variableDeclarations = [];
164+
}
166165

167-
scope.variableDeclarations.push(declaration);
166+
scope.variableDeclarations.push(declaration);
168167

169-
if (scope.type === ScopeType.Switch) {
170-
declaration = undefined;
171-
}
168+
if (scope.type === ScopeType.Switch) {
169+
declaration = undefined;
172170
}
173171
} else if (rhs) {
174172
// global
@@ -178,7 +176,7 @@ export function createLocalOrExportedOrGlobalDeclaration(
178176
}
179177
}
180178

181-
if (!context.options.noHoisting && isFunctionDeclaration) {
179+
if (isFunctionDeclaration) {
182180
// Remember function definitions for hoisting later
183181
const functionSymbolId = (lhs as lua.Identifier).symbolId;
184182
const scope = peekScope(context);

src/transformation/utils/scope.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,10 +92,6 @@ export function popScope(context: TransformationContext): Scope {
9292
}
9393

9494
export function performHoisting(context: TransformationContext, statements: lua.Statement[]): lua.Statement[] {
95-
if (context.options.noHoisting) {
96-
return statements;
97-
}
98-
9995
const scope = peekScope(context);
10096
let result = statements;
10197
result = hoistFunctionDefinitions(context, scope, result);

src/transformation/utils/symbols.ts

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@ import * as ts from "typescript";
22
import * as lua from "../../LuaAST";
33
import { getOrUpdate } from "../../utils";
44
import { TransformationContext } from "../context";
5-
import { referencedBeforeDeclaration } from "./diagnostics";
65
import { markSymbolAsReferencedInCurrentScopes } from "./scope";
7-
import { getFirstDeclarationInFile } from "./typescript";
86

97
const symbolIdCounters = new WeakMap<TransformationContext, number>();
108
function nextSymbolId(context: TransformationContext): lua.SymbolId {
@@ -46,14 +44,6 @@ export function trackSymbolReference(
4644
symbolInfo.set(symbolId, { symbol, firstSeenAtPos: identifier.pos });
4745
}
4846

49-
if (context.options.noHoisting) {
50-
// Check for reference-before-declaration
51-
const declaration = getFirstDeclarationInFile(symbol, context.sourceFile);
52-
if (declaration && identifier.pos < declaration.pos) {
53-
context.diagnostics.push(referencedBeforeDeclaration(identifier, identifier.text));
54-
}
55-
}
56-
5747
markSymbolAsReferencedInCurrentScopes(context, symbolId, identifier);
5848

5949
return symbolId;

src/transformation/visitors/binary-expression/destructuring-assignments.ts

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -38,20 +38,20 @@ export function transformDestructuringAssignment(
3838
node: ts.DestructuringAssignment,
3939
root: lua.Expression
4040
): lua.Statement[] {
41-
switch (node.left.kind) {
42-
case ts.SyntaxKind.ObjectLiteralExpression:
43-
return transformObjectDestructuringAssignment(context, node as ts.ObjectDestructuringAssignment, root);
44-
case ts.SyntaxKind.ArrayLiteralExpression:
45-
return transformArrayDestructuringAssignment(context, node as ts.ArrayDestructuringAssignment, root);
46-
}
41+
return transformAssignmentPattern(context, node.left, root);
4742
}
4843

49-
function transformArrayDestructuringAssignment(
44+
export function transformAssignmentPattern(
5045
context: TransformationContext,
51-
node: ts.ArrayDestructuringAssignment,
46+
node: ts.AssignmentPattern,
5247
root: lua.Expression
5348
): lua.Statement[] {
54-
return transformArrayLiteralAssignmentPattern(context, node.left, root);
49+
switch (node.kind) {
50+
case ts.SyntaxKind.ObjectLiteralExpression:
51+
return transformObjectLiteralAssignmentPattern(context, node, root);
52+
case ts.SyntaxKind.ArrayLiteralExpression:
53+
return transformArrayLiteralAssignmentPattern(context, node, root);
54+
}
5555
}
5656

5757
function transformArrayLiteralAssignmentPattern(
@@ -136,14 +136,6 @@ function transformArrayLiteralAssignmentPattern(
136136
});
137137
}
138138

139-
function transformObjectDestructuringAssignment(
140-
context: TransformationContext,
141-
node: ts.ObjectDestructuringAssignment,
142-
root: lua.Expression
143-
): lua.Statement[] {
144-
return transformObjectLiteralAssignmentPattern(context, node.left, root);
145-
}
146-
147139
function transformObjectLiteralAssignmentPattern(
148140
context: TransformationContext,
149141
node: ts.ObjectLiteralExpression,

src/transformation/visitors/function.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ export const transformFunctionDeclaration: FunctionVisitor<ts.FunctionDeclaratio
265265
const name = node.name ? transformIdentifier(context, node.name) : lua.createAnonymousIdentifier();
266266

267267
// Remember symbols referenced in this function for hoisting later
268-
if (!context.options.noHoisting && name.symbolId !== undefined) {
268+
if (name.symbolId !== undefined) {
269269
const scope = peekScope(context);
270270
if (!scope.functionDefinitions) {
271271
scope.functionDefinitions = new Map();

0 commit comments

Comments
 (0)