Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: tap in Class visitor to play nicely with class transforms
- Loading branch information
Showing
21 changed files
with
243 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
...el-plugin-proposal-class-static-block/test/fixtures/class-static-block/non-static/exec.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
class Foo { | ||
bar = 21; | ||
static { | ||
this.foo = this.bar; | ||
} | ||
} | ||
expect(Foo.foo).toBe(undefined); |
7 changes: 7 additions & 0 deletions
7
.../babel-plugin-proposal-class-static-block/test/fixtures/integration/class-binding/exec.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
class Foo { | ||
static { | ||
this.foo = Foo.bar; | ||
} | ||
static bar = 42; | ||
} | ||
expect(Foo.foo).toBe(42); |
7 changes: 7 additions & 0 deletions
7
...babel-plugin-proposal-class-static-block/test/fixtures/integration/class-binding/input.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
class Foo { | ||
static { | ||
this.foo = Foo.bar; | ||
} | ||
static bar = 42; | ||
} | ||
expect(Foo.foo).toBe(42); |
10 changes: 10 additions & 0 deletions
10
...abel-plugin-proposal-class-static-block/test/fixtures/integration/class-binding/output.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
class Foo {} | ||
|
||
babelHelpers.defineProperty(Foo, "bar", 42); | ||
var _ = { | ||
writable: true, | ||
value: (() => { | ||
Foo.foo = Foo.bar; | ||
})() | ||
}; | ||
expect(Foo.foo).toBe(42); |
7 changes: 7 additions & 0 deletions
7
...el-plugin-proposal-class-static-block/test/fixtures/integration/class-declaration/exec.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
class Foo { | ||
static { | ||
this.foo = this.bar; | ||
} | ||
static bar = 42; | ||
} | ||
expect(Foo.foo).toBe(42); |
7 changes: 7 additions & 0 deletions
7
...l-plugin-proposal-class-static-block/test/fixtures/integration/class-declaration/input.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
class Foo { | ||
static { | ||
this.foo = this.bar; | ||
} | ||
static bar = 42; | ||
} | ||
expect(Foo.foo).toBe(42); |
10 changes: 10 additions & 0 deletions
10
...-plugin-proposal-class-static-block/test/fixtures/integration/class-declaration/output.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
class Foo {} | ||
|
||
babelHelpers.defineProperty(Foo, "bar", 42); | ||
var _ = { | ||
writable: true, | ||
value: (() => { | ||
Foo.foo = Foo.bar; | ||
})() | ||
}; | ||
expect(Foo.foo).toBe(42); |
6 changes: 6 additions & 0 deletions
6
...bel-plugin-proposal-class-static-block/test/fixtures/integration/class-expression/exec.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
class Foo { | ||
static { | ||
this.foo = 42; | ||
} | ||
} | ||
expect(Foo.foo).toBe(42); |
14 changes: 14 additions & 0 deletions
14
...el-plugin-proposal-class-static-block/test/fixtures/integration/in-class-heritage/exec.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
class Foo extends class extends class Base { | ||
static { | ||
this.qux = 21; | ||
} | ||
} { | ||
static { | ||
this.bar = 21; | ||
} | ||
} { | ||
static { | ||
this.foo = this.bar + this.qux; | ||
} | ||
} | ||
expect(Foo.foo).toBe(42); |
14 changes: 14 additions & 0 deletions
14
...l-plugin-proposal-class-static-block/test/fixtures/integration/in-class-heritage/input.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
class Foo extends class extends class Base { | ||
static { | ||
this.qux = 21; | ||
} | ||
} { | ||
static { | ||
this.bar = 21; | ||
} | ||
} { | ||
static { | ||
this.foo = this.bar + this.qux; | ||
} | ||
} | ||
expect(Foo.foo).toBe(42); |
21 changes: 21 additions & 0 deletions
21
...-plugin-proposal-class-static-block/test/fixtures/integration/in-class-heritage/output.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
var _class, _temp, _2, _class2, _temp2, _3; | ||
|
||
class Foo extends (_temp = _class = class extends (_temp2 = _class2 = class Base {}, _3 = { | ||
writable: true, | ||
value: (() => { | ||
_class2.qux = 21; | ||
})() | ||
}, _temp2) {}, _2 = { | ||
writable: true, | ||
value: (() => { | ||
_class.bar = 21; | ||
})() | ||
}, _temp) {} | ||
|
||
var _ = { | ||
writable: true, | ||
value: (() => { | ||
Foo.foo = Foo.bar + Foo.qux; | ||
})() | ||
}; | ||
expect(Foo.foo).toBe(42); |
8 changes: 8 additions & 0 deletions
8
...roposal-class-static-block/test/fixtures/integration/multiple-static-initializers/exec.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
class Foo { | ||
static #bar = 21; | ||
static { | ||
this.foo = this.#bar + this.qux; | ||
} | ||
static qux = 21; | ||
} | ||
expect(Foo.foo).toBe(42); |
8 changes: 8 additions & 0 deletions
8
.../babel-plugin-proposal-class-static-block/test/fixtures/integration/name-conflict/exec.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
class Foo { | ||
static #_ = 42; | ||
// static block can not be tranformed as `#_` here | ||
static { | ||
this.foo = this.#_; | ||
} | ||
} | ||
expect(Foo.foo).toBe(42); |
8 changes: 8 additions & 0 deletions
8
...babel-plugin-proposal-class-static-block/test/fixtures/integration/name-conflict/input.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
class Foo { | ||
static #_ = 42; | ||
// static block can not be tranformed as `#_` here | ||
static { | ||
this.foo = this.#_; | ||
} | ||
} | ||
expect(Foo.foo).toBe(42); |
15 changes: 15 additions & 0 deletions
15
...abel-plugin-proposal-class-static-block/test/fixtures/integration/name-conflict/output.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
function _classStaticPrivateFieldSpecGet(receiver, classConstructor, descriptor) { if (receiver !== classConstructor) { throw new TypeError("Private static access of wrong provenance"); } if (descriptor.get) { return descriptor.get.call(receiver); } return descriptor.value; } | ||
|
||
class Foo {} | ||
|
||
var _ = { | ||
writable: true, | ||
value: 42 | ||
}; | ||
var _2 = { | ||
writable: true, | ||
value: (() => { | ||
Foo.foo = _classStaticPrivateFieldSpecGet(Foo, Foo, _); | ||
})() | ||
}; | ||
expect(Foo.foo).toBe(42); |
7 changes: 7 additions & 0 deletions
7
...ges/babel-plugin-proposal-class-static-block/test/fixtures/integration/non-static/exec.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
class Foo { | ||
bar = 21; | ||
static { | ||
this.foo = this.bar; | ||
} | ||
} | ||
expect(Foo.foo).toBe(undefined); |
7 changes: 7 additions & 0 deletions
7
packages/babel-plugin-proposal-class-static-block/test/fixtures/integration/options.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"plugins": [ | ||
"proposal-class-static-block", | ||
"proposal-class-properties", | ||
"external-helpers" | ||
] | ||
} |
8 changes: 8 additions & 0 deletions
8
...gin-proposal-class-static-block/test/fixtures/integration/private-elements-access/exec.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
let getFoo; | ||
class Foo { | ||
static #foo = 42; | ||
static { | ||
getFoo = () => this.#foo; | ||
} | ||
} | ||
expect(getFoo()).toBe(42); |
11 changes: 11 additions & 0 deletions
11
...babel-plugin-proposal-class-static-block/test/fixtures/integration/super-property/exec.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
class Foo extends class { | ||
static { | ||
this.bar = 42; | ||
} | ||
} { | ||
static bar = 21; | ||
static { | ||
this.foo = super.bar; | ||
} | ||
} | ||
expect(Foo.foo).toBe(42); |
42 changes: 42 additions & 0 deletions
42
packages/babel-plugin-proposal-class-static-block/test/plugin-ordering.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import * as babel from "@babel/core"; | ||
import proposalClassStaticBlock from "../lib/index.js"; | ||
|
||
describe("plugin ordering", () => { | ||
it("should throw when @babel/plugin-proposal-class-static-block is after class features plugin", () => { | ||
const source = `class Foo { | ||
static { | ||
this.foo = Foo.bar; | ||
} | ||
static bar = 42; | ||
} | ||
`; | ||
expect(() => { | ||
babel.transform(source, { | ||
filename: "example.js", | ||
highlightCode: false, | ||
configFile: false, | ||
babelrc: false, | ||
plugins: [ | ||
"@babel/plugin-proposal-class-properties", | ||
proposalClassStaticBlock, | ||
], | ||
}); | ||
}).toThrowErrorMatchingInlineSnapshot(` | ||
"/Users/jh/code/babel/example.js: Incorrect plugin orders, \`@babel/plugin-proposal-class-static-block\` should be placed before class features plugins | ||
{ | ||
\\"plugins\\": [ | ||
\\"@babel/plugin-proposal-class-static-block\\", | ||
\\"@babel/plugin-proposal-private-property-in-object\\", | ||
\\"@babel/plugin-proposal-private-methods\\", | ||
\\"@babel/plugin-proposal-class-properties\\", | ||
] | ||
} | ||
1 | class Foo { | ||
> 2 | static { | ||
| ^ | ||
3 | this.foo = Foo.bar; | ||
4 | } | ||
5 | static bar = 42;" | ||
`); | ||
}); | ||
}); |