X Tutup
Skip to content

Commit 31a3223

Browse files
authored
Merge branch 'TypeScriptToLua:master' into master
2 parents f4d6210 + 278ead6 commit 31a3223

File tree

37 files changed

+1128
-301
lines changed

37 files changed

+1128
-301
lines changed

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
# Changelog
22

3+
## 1.16.0
4+
5+
- Upgraded TypeScript to 5.1.3.
6+
- Added support for [TypeScript 5.0 decorators](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-5-0.html#decorators).
7+
- Old-style decorators will still work as long as you have `experimentalDecorators` configured, otherwise the new standard is used.
8+
- Added support for [class static initialization blocks](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes/Static_initialization_blocks).
9+
- Fixed a bug causing the `tstl` object in tsconfig.json not to be properly extended when extending a tsconfig from node_modules.
10+
311
## 1.15.0
412

513
- Using `extends` in tsconfig.json now also correctly merges settings in the `tstl` block (shallow merge).

package-lock.json

Lines changed: 11 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "typescript-to-lua",
3-
"version": "1.15.1",
3+
"version": "1.16.2",
44
"description": "A generic TypeScript to Lua transpiler. Write your code in TypeScript and publish Lua!",
55
"repository": "https://github.com/TypeScriptToLua/TypeScriptToLua",
66
"homepage": "https://typescripttolua.github.io/",
@@ -42,7 +42,7 @@
4242
"node": ">=16.10.0"
4343
},
4444
"peerDependencies": {
45-
"typescript": "^5.0.2"
45+
"typescript": "~5.1.3"
4646
},
4747
"dependencies": {
4848
"@typescript-to-lua/language-extensions": "1.0.0",
@@ -70,6 +70,6 @@
7070
"prettier": "^2.8.4",
7171
"ts-jest": "^29.1.0",
7272
"ts-node": "^10.9.1",
73-
"typescript": "^5.0.4"
73+
"typescript": "~5.1.3"
7474
}
7575
}

src/LuaLib.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ export enum LuaLibFeature {
3838
CloneDescriptor = "CloneDescriptor",
3939
CountVarargs = "CountVarargs",
4040
Decorate = "Decorate",
41+
DecorateLegacy = "DecorateLegacy",
4142
DecorateParam = "DecorateParam",
4243
Delete = "Delete",
4344
DelegatedYield = "DelegatedYield",

src/lualib/Decorate.ts

Lines changed: 8 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,20 @@
11
/**
2-
* SEE: https://github.com/Microsoft/TypeScript/blob/master/src/compiler/transformers/ts.ts#L3598
2+
* TypeScript 5.0 decorators
33
*/
4-
import { __TS__ObjectGetOwnPropertyDescriptor } from "./ObjectGetOwnPropertyDescriptor";
5-
import { __TS__SetDescriptor } from "./SetDescriptor";
64
import { Decorator } from "./Decorator";
75

8-
export function __TS__Decorate<TTarget extends AnyTable, TKey extends keyof TTarget>(
9-
this: void,
10-
decorators: Array<Decorator<TTarget, TKey>>,
11-
target: TTarget,
12-
key?: TKey,
13-
desc?: any
6+
export function __TS__Decorate<TClass, TTarget>(
7+
this: TClass,
8+
originalValue: TTarget,
9+
decorators: Array<Decorator<TTarget>>,
10+
context: DecoratorContext
1411
): TTarget {
15-
let result = target;
12+
let result = originalValue;
1613

1714
for (let i = decorators.length; i >= 0; i--) {
1815
const decorator = decorators[i];
1916
if (decorator !== undefined) {
20-
const oldResult = result;
21-
22-
if (key === undefined) {
23-
result = decorator(result);
24-
} else if (desc === true) {
25-
const value = rawget(target, key);
26-
const descriptor = __TS__ObjectGetOwnPropertyDescriptor(target, key) ?? {
27-
configurable: true,
28-
writable: true,
29-
value,
30-
};
31-
const desc = decorator(target, key, descriptor) || descriptor;
32-
const isSimpleValue = desc.configurable === true && desc.writable === true && !desc.get && !desc.set;
33-
if (isSimpleValue) {
34-
rawset(target, key, desc.value);
35-
} else {
36-
__TS__SetDescriptor(target, key, { ...descriptor, ...desc });
37-
}
38-
} else if (desc === false) {
39-
result = decorator(target, key, desc);
40-
} else {
41-
result = decorator(target, key);
42-
}
43-
44-
result = result || oldResult;
17+
result = decorator.call(this, result, context) ?? result;
4518
}
4619
}
4720

src/lualib/DecorateLegacy.ts

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/**
2+
* Old-style decorators, activated by enabling the experimentalDecorators flag
3+
*/
4+
import { __TS__ObjectGetOwnPropertyDescriptor } from "./ObjectGetOwnPropertyDescriptor";
5+
import { __TS__SetDescriptor } from "./SetDescriptor";
6+
7+
export type LegacyDecorator<TTarget extends AnyTable, TKey extends keyof TTarget> = (
8+
target: TTarget,
9+
key?: TKey,
10+
descriptor?: PropertyDescriptor
11+
) => TTarget;
12+
13+
export function __TS__DecorateLegacy<TTarget extends AnyTable, TKey extends keyof TTarget>(
14+
this: void,
15+
decorators: Array<LegacyDecorator<TTarget, TKey>>,
16+
target: TTarget,
17+
key?: TKey,
18+
desc?: any
19+
): TTarget {
20+
let result = target;
21+
22+
for (let i = decorators.length; i >= 0; i--) {
23+
const decorator = decorators[i];
24+
if (decorator !== undefined) {
25+
const oldResult = result;
26+
27+
if (key === undefined) {
28+
result = decorator(result);
29+
} else if (desc === true) {
30+
const value = rawget(target, key);
31+
const descriptor = __TS__ObjectGetOwnPropertyDescriptor(target, key) ?? {
32+
configurable: true,
33+
writable: true,
34+
value,
35+
};
36+
const desc = decorator(target, key, descriptor) || descriptor;
37+
const isSimpleValue = desc.configurable === true && desc.writable === true && !desc.get && !desc.set;
38+
if (isSimpleValue) {
39+
rawset(target, key, desc.value);
40+
} else {
41+
__TS__SetDescriptor(target, key, { ...descriptor, ...desc });
42+
}
43+
} else if (desc === false) {
44+
result = decorator(target, key, desc);
45+
} else {
46+
result = decorator(target, key);
47+
}
48+
49+
result = result || oldResult;
50+
}
51+
}
52+
53+
return result;
54+
}

src/lualib/DecorateParam.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Decorator } from "./Decorator";
1+
import type { LegacyDecorator } from "./DecorateLegacy";
22

33
type ParamDecorator<TTarget extends AnyTable, TKey extends keyof TTarget> = (
44
target: TTarget,
@@ -9,6 +9,6 @@ export function __TS__DecorateParam<TTarget extends AnyTable, TKey extends keyof
99
this: void,
1010
paramIndex: number,
1111
decorator: ParamDecorator<TTarget, TKey>
12-
): Decorator<TTarget, TKey> {
12+
): LegacyDecorator<TTarget, TKey> {
1313
return (target: TTarget, key?: TKey) => decorator(target, key, paramIndex);
1414
}

src/lualib/Decorator.d.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1 @@
1-
export type Decorator<TTarget extends AnyTable, TKey extends keyof TTarget> = (
2-
target: TTarget,
3-
key?: TKey,
4-
descriptor?: PropertyDescriptor
5-
) => TTarget;
1+
export type Decorator<TTarget> = (target: TTarget, context: DecoratorContext) => TTarget;

src/transformation/utils/diagnostics.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,3 +168,7 @@ export const invalidSpreadInCallExtension = createErrorDiagnosticFactory(
168168
export const cannotAssignToNodeOfKind = createErrorDiagnosticFactory(
169169
(kind: lua.SyntaxKind) => `Cannot create assignment assigning to a node of type ${lua.SyntaxKind[kind]}.`
170170
);
171+
172+
export const incompleteFieldDecoratorWarning = createWarningDiagnosticFactory(
173+
"You are using a class field decorator, note that tstl ignores returned value initializers!"
174+
);

src/transformation/utils/function-context.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ function hasNoSelfAncestor(declaration: ts.Declaration): boolean {
3030

3131
function getExplicitThisParameter(signatureDeclaration: ts.SignatureDeclaration): ts.ParameterDeclaration | undefined {
3232
const param = signatureDeclaration.parameters[0];
33-
if (param && ts.isIdentifier(param.name) && param.name.originalKeywordKind === ts.SyntaxKind.ThisKeyword) {
33+
if (param && ts.isIdentifier(param.name) && ts.identifierToKeywordKind(param.name) === ts.SyntaxKind.ThisKeyword) {
3434
return param;
3535
}
3636
}

0 commit comments

Comments
 (0)
X Tutup