Skip to content

Commit

Permalink
feat(ts): add TS v3.7/3.8 language features
Browse files Browse the repository at this point in the history
  • Loading branch information
spencercorwin committed Feb 27, 2020
1 parent db6c5df commit 2f64dd9
Show file tree
Hide file tree
Showing 20 changed files with 717 additions and 22 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"changes": [
{
"packageName": "@neo-one/smart-contract-compiler",
"comment": "Add support for new language features in TS v3.7, v3.8",
"type": "minor"
}
],
"packageName": "@neo-one/smart-contract-compiler",
"email": "spencercorwin@icloud.com"
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
"changes": [
{
"packageName": "@neo-one/smart-contract-compiler",
"comment": "Upgrade TS to v3.8.1-rc. Add support for Nullish Coalescing",
"comment": "Upgrade TS to v3.8.1-rc. Add support for Nullish Coalescing.",
"type": "minor"
}
],
"packageName": "@neo-one/smart-contract-compiler",
"email": "spencercorwin@icloud.com"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"changes": [
{
"packageName": "@neo-one/typescript-concatenator",
"comment": "Add support for new language features in TS v3.7, v3.8",
"type": "minor"
}
],
"packageName": "@neo-one/typescript-concatenator",
"email": "spencercorwin@icloud.com"
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
"changes": [
{
"packageName": "@neo-one/typescript-concatenator",
"comment": "Upgrade TS to v3.8.1-rc. Add support for namespace exports",
"comment": "Upgrade TS to v3.8.1-rc. Add support for namespace exports.",
"type": "minor"
}
],
"packageName": "@neo-one/typescript-concatenator",
"email": "spencercorwin@icloud.com"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,74 @@ describe('ClassDeclarationCompiler', () => {
`);
});

test('basic class with ECMAScript private member, inaccessible', async () => {
helpers.compileString(
`
class Foo {
#x: string = 'bar';
['bar'](): string {
return this.#x;
}
}
const f = new Foo();
f.#x;
`,
{ type: 'error' },
);
});

test('ECMAScript private member, no public modifier allowed', async () => {
helpers.compileString(
`
class Foo {
public #x: string = 'bar';
}
`,
{ type: 'error' },
);
});

test('ECMAScript private member, no private modifier allowed', async () => {
helpers.compileString(
`
class Foo {
private #x: string = 'bar';
}
`,
{ type: 'error' },
);
});

test('ECMAScript private member, extends does not override private member', async () => {
await helpers.executeString(
`
class Foo {
#x: string = 'bar';
getX(): string {
return this.#x;
}
}
class Bar extends Foo {
#x: string = 'baz';
getX(): string {
return this.#x;
}
}
const foo = new Foo();
const bar = new Bar();
assertEqual(foo.getX(), 'bar');
assertEqual(bar.getX(), 'baz');
`,
);
});

test('basic class with get accessor', async () => {
await helpers.executeString(`
class Foo {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,26 @@ describe('TypeAliasDeclarationCompiler', () => {
}
`);
});

test('recursive type alias does not emit', async () => {
await helpers.executeString(`
type Json =
| string
| number
| boolean
| null
| { [property: string]: Json }
| Json[];
type VirtualNode =
| string
| [string, { [key: string]: any }, ...VirtualNode[]];
const myNode: VirtualNode =
["div", { id: "parent" },
["div", { id: "first-child" }, "I'm the first child"],
["div", { id: "second-child" }, "I'm the second child"]
];
`);
});
});
Original file line number Diff line number Diff line change
@@ -1,5 +1,40 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`ClassDeclarationCompiler ECMAScript private member, no private modifier allowed 1`] = `
"snippetCode.ts (3,9): An accessibility modifier cannot be used with a private identifier.
1 |
2 | class Foo {
> 3 | private #x: string = 'bar';
| ^
4 | }
5 |
"
`;

exports[`ClassDeclarationCompiler ECMAScript private member, no public modifier allowed 1`] = `
"snippetCode.ts (3,9): An accessibility modifier cannot be used with a private identifier.
1 |
2 | class Foo {
> 3 | public #x: string = 'bar';
| ^
4 | }
5 |
"
`;

exports[`ClassDeclarationCompiler basic class with ECMAScript private member, inaccessible 1`] = `
"snippetCode.ts (11,9): Property '#x' is not accessible outside class 'Foo' because it has a private identifier.
9 |
10 | const f = new Foo();
> 11 | f.#x;
| ^
12 |
"
`;

exports[`ClassDeclarationCompiler decorators 1`] = `
"snippetCode.ts (7,9): Custom decorators are not supported
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,15 @@ describe('AwaitFunctionCompiler', () => {
{ type: 'error' },
);
});

test('await', async () => {
helpers.compileString(
`
await 2;
export {};
`,
{ type: 'error' },
);
});
});

0 comments on commit 2f64dd9

Please sign in to comment.