Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(compiler): detect unimported decorators #681

Merged
merged 5 commits into from
Oct 1, 2018

Conversation

apapko
Copy link
Collaborator

@apapko apapko commented Sep 26, 2018

Details

If babel-plugin-transform-lwc-class transform doesn't do early detection of a decorator usage that has not been imported from lwc, the issue is then caught by the babel with a bogus message. This PR adds validation earlier at the program visitor.
Fixes #601

Does this PR introduce a breaking change?

  • Yes
  • No

@apapko apapko changed the title Apapko/unused decorator visitor feat(compiler): detect unimported decorator visitor Sep 26, 2018
@apapko apapko force-pushed the apapko/unused-decorator-visitor branch from e2c9a42 to 648b5b9 Compare September 27, 2018 00:05
@salesforce-best-lwc-internal
Copy link

Benchmark results

Base commit: e0a8d76 | Target commit: e2c9a42

2 similar comments
@salesforce-best-lwc-internal
Copy link

Benchmark results

Base commit: e0a8d76 | Target commit: e2c9a42

@salesforce-best-lwc-internal
Copy link

Benchmark results

Base commit: e0a8d76 | Target commit: e2c9a42

@apapko apapko changed the title feat(compiler): detect unimported decorator visitor feat(compiler): detect unimported decorators Sep 27, 2018
@salesforce-best-lwc-internal
Copy link

Benchmark results

Base commit: faf9cd4 | Target commit: 9291d72

@apapko apapko force-pushed the apapko/unused-decorator-visitor branch from 9291d72 to 648b5b9 Compare September 27, 2018 16:14
@@ -26,8 +28,22 @@ module.exports = function LwcClassTransform(api) {
{
Program: {
exit(path, state) {
const visitors = mergeVisitors([
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's move the logic out of the file, we should not pollute the entry point.

const visitors = mergeVisitors([
classProperty(api, { loose: true }).visitor,
{
Decorator(path) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should add a comment here to explain why the Decorator visitor works here.

}
});

pluginTest('compiler should throw when "track" decorator is used in the inner class but was not imported from lwc', `
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do have this test?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that was testing the decorator usage with inheritance, but with our new logic to check decorators on exit this no longer is needed.

@apapko apapko force-pushed the apapko/unused-decorator-visitor branch from 648b5b9 to 5ee44d2 Compare September 27, 2018 17:16
@salesforce-best-lwc-internal
Copy link

Benchmark results

Base commit: cc705d0 | Target commit: 5ee44d2

lwc-engine-benchmark

table-append-1k metric base(cc705d0) target(5ee44d2) trend
benchmark-table/append/1k duration 159.00 (±7.10 ms) 161.45 (±5.20 ms) +2.4ms (1.5%) 👌
table-clear-1k metric base(cc705d0) target(5ee44d2) trend
benchmark-table/clear/1k duration 12.30 (±0.95 ms) 12.15 (±0.75 ms) -0.2ms (1.2%) 👌
table-create-10k metric base(cc705d0) target(5ee44d2) trend
benchmark-table/create/10k duration 936.80 (±9.55 ms) 938.95 (±9.70 ms) +2.2ms (0.2%) 👌
table-create-1k metric base(cc705d0) target(5ee44d2) trend
benchmark-table/create/1k duration 110.20 (±1.80 ms) 109.95 (±2.30 ms) -0.3ms (0.2%) 👌
table-update-10th-1k metric base(cc705d0) target(5ee44d2) trend
benchmark-table/update-10th/1k duration 98.60 (±3.55 ms) 90.50 (±6.40 ms) -8.1ms (8.2%) 👍
tablecmp-append-1k metric base(cc705d0) target(5ee44d2) trend
benchmark-table-component/append/1k duration 239.50 (±7.20 ms) 242.00 (±7.20 ms) +2.5ms (1.0%) 👌
tablecmp-clear-1k metric base(cc705d0) target(5ee44d2) trend
benchmark-table-component/clear/1k duration 20.15 (±2.05 ms) 20.95 (±1.85 ms) +0.8ms (4.0%) 👌
tablecmp-create-10k metric base(cc705d0) target(5ee44d2) trend
benchmark-table-component/create/10k duration 1670.65 (±14.25 ms) 1665.80 (±15.70 ms) -4.8ms (0.3%) 👌
tablecmp-create-1k metric base(cc705d0) target(5ee44d2) trend
benchmark-table-component/create/1k duration 190.40 (±6.60 ms) 186.30 (±6.10 ms) -4.1ms (2.2%) 👍
tablecmp-update-10th-1k metric base(cc705d0) target(5ee44d2) trend
benchmark-table-component/update-10th/1k duration 83.70 (±5.50 ms) 83.85 (±5.40 ms) +0.1ms (0.2%) 👌
wc-append-1k metric base(cc705d0) target(5ee44d2) trend
benchmark-table-wc/append/1k duration 277.30 (±13.50 ms) 282.20 (±14.55 ms) +4.9ms (1.8%) 👌
wc-clear-1k metric base(cc705d0) target(5ee44d2) trend
benchmark-table-wc/clear/1k duration 29.75 (±2.35 ms) 30.55 (±2.35 ms) +0.8ms (2.7%) 👌
wc-create-10k metric base(cc705d0) target(5ee44d2) trend
benchmark-table-wc/create/10k duration 2148.35 (±13.90 ms) 2142.55 (±13.10 ms) -5.8ms (0.3%) 👌
wc-create-1k metric base(cc705d0) target(5ee44d2) trend
benchmark-table-wc/create/1k duration 229.00 (±6.20 ms) 226.70 (±5.95 ms) -2.3ms (1.0%) 👌
wc-update-10th-1k metric base(cc705d0) target(5ee44d2) trend
benchmark-table-wc/update-10th/1k duration 85.05 (±5.00 ms) 82.65 (±7.55 ms) -2.4ms (2.8%) 👌

@salesforce-best-lwc-internal
Copy link

Benchmark results

Base commit: cc705d0 | Target commit: 8a761bc

lwc-engine-benchmark

table-append-1k metric base(cc705d0) target(8a761bc) trend
benchmark-table/append/1k duration 159.00 (±7.10 ms) 163.45 (±3.65 ms) +4.4ms (2.8%) 👎
table-clear-1k metric base(cc705d0) target(8a761bc) trend
benchmark-table/clear/1k duration 12.30 (±0.95 ms) 13.55 (±0.95 ms) +1.3ms (10.2%) 👎
table-create-10k metric base(cc705d0) target(8a761bc) trend
benchmark-table/create/10k duration 936.80 (±9.55 ms) 948.50 (±9.30 ms) +11.7ms (1.2%) 👎
table-create-1k metric base(cc705d0) target(8a761bc) trend
benchmark-table/create/1k duration 110.20 (±1.80 ms) 112.30 (±2.15 ms) +2.1ms (1.9%) 👎
table-update-10th-1k metric base(cc705d0) target(8a761bc) trend
benchmark-table/update-10th/1k duration 98.60 (±3.55 ms) 100.05 (±2.25 ms) +1.5ms (1.5%) 👌
tablecmp-append-1k metric base(cc705d0) target(8a761bc) trend
benchmark-table-component/append/1k duration 239.50 (±7.20 ms) 243.45 (±10.10 ms) +3.9ms (1.6%) 👎
tablecmp-clear-1k metric base(cc705d0) target(8a761bc) trend
benchmark-table-component/clear/1k duration 20.15 (±2.05 ms) 20.95 (±2.05 ms) +0.8ms (4.0%) 👎
tablecmp-create-10k metric base(cc705d0) target(8a761bc) trend
benchmark-table-component/create/10k duration 1670.65 (±14.25 ms) 1661.95 (±13.70 ms) -8.7ms (0.5%) 👍
tablecmp-create-1k metric base(cc705d0) target(8a761bc) trend
benchmark-table-component/create/1k duration 190.40 (±6.60 ms) 182.80 (±6.70 ms) -7.6ms (4.0%) 👍
tablecmp-update-10th-1k metric base(cc705d0) target(8a761bc) trend
benchmark-table-component/update-10th/1k duration 83.70 (±5.50 ms) 82.05 (±5.35 ms) -1.7ms (2.0%) 👌
wc-append-1k metric base(cc705d0) target(8a761bc) trend
benchmark-table-wc/append/1k duration 277.30 (±13.50 ms) 277.20 (±15.35 ms) -0.1ms (0.0%) 👌
wc-clear-1k metric base(cc705d0) target(8a761bc) trend
benchmark-table-wc/clear/1k duration 29.75 (±2.35 ms) 31.20 (±2.45 ms) +1.4ms (4.9%) 👌
wc-create-10k metric base(cc705d0) target(8a761bc) trend
benchmark-table-wc/create/10k duration 2148.35 (±13.90 ms) 2196.20 (±13.50 ms) +47.8ms (2.2%) 👎
wc-create-1k metric base(cc705d0) target(8a761bc) trend
benchmark-table-wc/create/1k duration 229.00 (±6.20 ms) 225.45 (±6.95 ms) -3.6ms (1.6%) 👌
wc-update-10th-1k metric base(cc705d0) target(8a761bc) trend
benchmark-table-wc/update-10th/1k duration 85.05 (±5.00 ms) 84.45 (±8.40 ms) -0.6ms (0.7%) 👌

Copy link
Member

@pmdartus pmdartus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@salesforce-best-lwc-internal
Copy link

Benchmark results

Base commit: 545c1b1 | Target commit: 8a761bc

lwc-engine-benchmark

table-append-1k metric base(545c1b1) target(8a761bc) trend
benchmark-table/append/1k duration 165.30 (±6.50 ms) 165.25 (±3.70 ms) -0.1ms (0.0%) 👌
table-clear-1k metric base(545c1b1) target(8a761bc) trend
benchmark-table/clear/1k duration 13.30 (±0.55 ms) 13.20 (±0.85 ms) -0.1ms (0.8%) 👌
table-create-10k metric base(545c1b1) target(8a761bc) trend
benchmark-table/create/10k duration 948.85 (±8.00 ms) 949.45 (±8.50 ms) +0.6ms (0.1%) 👌
table-create-1k metric base(545c1b1) target(8a761bc) trend
benchmark-table/create/1k duration 112.75 (±2.35 ms) 112.15 (±2.35 ms) -0.6ms (0.5%) 👍
table-update-10th-1k metric base(545c1b1) target(8a761bc) trend
benchmark-table/update-10th/1k duration 92.50 (±6.40 ms) 99.00 (±2.20 ms) +6.5ms (7.0%) 👌
tablecmp-append-1k metric base(545c1b1) target(8a761bc) trend
benchmark-table-component/append/1k duration 253.85 (±6.65 ms) 248.25 (±7.65 ms) -5.6ms (2.2%) 👍
tablecmp-clear-1k metric base(545c1b1) target(8a761bc) trend
benchmark-table-component/clear/1k duration 22.30 (±1.50 ms) 22.05 (±2.00 ms) -0.3ms (1.1%) 👌
tablecmp-create-10k metric base(545c1b1) target(8a761bc) trend
benchmark-table-component/create/10k duration 1712.50 (±15.20 ms) 1671.45 (±13.10 ms) -41.0ms (2.4%) 👍
tablecmp-create-1k metric base(545c1b1) target(8a761bc) trend
benchmark-table-component/create/1k duration 189.15 (±6.95 ms) 188.75 (±8.05 ms) -0.4ms (0.2%) 👌
tablecmp-update-10th-1k metric base(545c1b1) target(8a761bc) trend
benchmark-table-component/update-10th/1k duration 82.80 (±6.70 ms) 82.35 (±7.55 ms) -0.5ms (0.5%) 👌
wc-append-1k metric base(545c1b1) target(8a761bc) trend
benchmark-table-wc/append/1k duration 281.05 (±14.70 ms) 270.85 (±18.85 ms) -10.2ms (3.6%) 👌
wc-clear-1k metric base(545c1b1) target(8a761bc) trend
benchmark-table-wc/clear/1k duration 30.65 (±2.40 ms) 31.80 (±2.05 ms) +1.1ms (3.8%) 👌
wc-create-10k metric base(545c1b1) target(8a761bc) trend
benchmark-table-wc/create/10k duration 2149.75 (±17.55 ms) 2171.25 (±16.10 ms) +21.5ms (1.0%) 👎
wc-create-1k metric base(545c1b1) target(8a761bc) trend
benchmark-table-wc/create/1k duration 226.20 (±4.55 ms) 227.40 (±4.95 ms) +1.2ms (0.5%) 👌
wc-update-10th-1k metric base(545c1b1) target(8a761bc) trend
benchmark-table-wc/update-10th/1k duration 88.20 (±7.60 ms) 88.90 (±6.45 ms) +0.7ms (0.8%) 👌

@salesforce-best-lwc-internal
Copy link

Benchmark results

Base commit: 545c1b1 | Target commit: 8a761bc

@salesforce-best-lwc-internal
Copy link

Benchmark results

Base commit: 545c1b1 | Target commit: 8a761bc

lwc-engine-benchmark

table-append-1k metric base(545c1b1) target(8a761bc) trend
benchmark-table/append/1k duration 165.30 (±6.50 ms) 160.20 (±6.70 ms) -5.1ms (3.1%) 👍
table-clear-1k metric base(545c1b1) target(8a761bc) trend
benchmark-table/clear/1k duration 13.30 (±0.55 ms) 12.75 (±0.75 ms) -0.6ms (4.1%) 👍
table-create-10k metric base(545c1b1) target(8a761bc) trend
benchmark-table/create/10k duration 948.85 (±8.00 ms) 957.75 (±7.80 ms) +8.9ms (0.9%) 👎
table-create-1k metric base(545c1b1) target(8a761bc) trend
benchmark-table/create/1k duration 112.75 (±2.35 ms) 112.15 (±2.70 ms) -0.6ms (0.5%) 👌
table-update-10th-1k metric base(545c1b1) target(8a761bc) trend
benchmark-table/update-10th/1k duration 92.50 (±6.40 ms) 88.25 (±3.35 ms) -4.3ms (4.6%) 👍
tablecmp-append-1k metric base(545c1b1) target(8a761bc) trend
benchmark-table-component/append/1k duration 253.85 (±6.65 ms) 247.60 (±6.45 ms) -6.3ms (2.5%) 👍
tablecmp-clear-1k metric base(545c1b1) target(8a761bc) trend
benchmark-table-component/clear/1k duration 22.30 (±1.50 ms) 21.30 (±2.00 ms) -1.0ms (4.5%) 👌
tablecmp-create-10k metric base(545c1b1) target(8a761bc) trend
benchmark-table-component/create/10k duration 1712.50 (±15.20 ms) 1690.00 (±13.05 ms) -22.5ms (1.3%) 👍
tablecmp-create-1k metric base(545c1b1) target(8a761bc) trend
benchmark-table-component/create/1k duration 189.15 (±6.95 ms) 189.25 (±4.65 ms) +0.1ms (0.1%) 👌
tablecmp-update-10th-1k metric base(545c1b1) target(8a761bc) trend
benchmark-table-component/update-10th/1k duration 82.80 (±6.70 ms) 86.15 (±6.95 ms) +3.4ms (4.0%) 👌
wc-append-1k metric base(545c1b1) target(8a761bc) trend
benchmark-table-wc/append/1k duration 281.05 (±14.70 ms) 266.15 (±16.95 ms) -14.9ms (5.3%) 👍
wc-clear-1k metric base(545c1b1) target(8a761bc) trend
benchmark-table-wc/clear/1k duration 30.65 (±2.40 ms) 30.80 (±2.10 ms) +0.1ms (0.5%) 👌
wc-create-10k metric base(545c1b1) target(8a761bc) trend
benchmark-table-wc/create/10k duration 2149.75 (±17.55 ms) 2153.80 (±13.25 ms) +4.1ms (0.2%) 👌
wc-create-1k metric base(545c1b1) target(8a761bc) trend
benchmark-table-wc/create/1k duration 226.20 (±4.55 ms) 225.85 (±5.35 ms) -0.3ms (0.2%) 👌
wc-update-10th-1k metric base(545c1b1) target(8a761bc) trend
benchmark-table-wc/update-10th/1k duration 88.20 (±7.60 ms) 84.00 (±6.10 ms) -4.2ms (4.8%) 👍

@diervo diervo merged commit 4788b26 into master Oct 1, 2018
@diervo diervo deleted the apapko/unused-decorator-visitor branch October 1, 2018 16:52
}
`, {
error: {
message: 'Invalid decorator usage. Supported decorators (api, wire, track) should be imported from "lwc"',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be or must be?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants