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

Decorators 2 Transform [WIP] #6107

Closed
wants to merge 23 commits into
base: master
from
Commits
Jump to file or symbol
Failed to load files and symbols.
+59 −0
Diff settings

Always

Just for now

Viewing a subset of changes. View all

configurability checks

  • Loading branch information...
peey committed Aug 29, 2017
commit 44465f2fcbc38bca77b9583ab9dff23369bf8471
@@ -357,8 +357,27 @@ helpers.decorateElement = template(`
for (let i = decorators.length - 1; i >= 0; i--) {
const decorator = decorators[i];
const shallowClone = {
configurable: previousDescriptor.descriptor.configurable,
enumerable: previousDescriptor.descriptor.enumerable,
writable: previousDescriptor.descriptor.writable,
value: previousDescriptor.descriptor.value
}
const result = decorator(previousDescriptor);
if (!shallowClone.configurable) {
let check =
result.descriptor.configurable === shallowClone.configurable &&
result.descriptor.enumerable === shallowClone.enumerable &&
result.descriptor.writable === shallowClone.writable &&
result.descriptor.value === shallowClone.value;
if (!check) {
throw new Error("Decorator tried to change unconfigurable property descriptor");
}
}
//TODO: why does .finisher exist on an elementDescriptor? the following conditional deviates from
//the spec because it uses result.finishers rather than result.descriptor.finisher
if (result.finishers) {
@@ -0,0 +1,40 @@
function set(prop, value) {
return function(descriptor) {
descriptor.descriptor[prop] = value;
return {descriptor, extras: [], finishers: []};
}
}
const msg = "Decorator tried to change unconfigurable property descriptor";
assert.throws(() => {
class Foo {
@set('configurable', true) @set('configurable', false) method() {}
}
}, msg);
assert.throws(() => {
class Foo {
@set('writable', false) @set('configurable', false) method() {}
}
}, msg);
assert.throws(() => {
class Foo {
@set('enumerable', true) @set('configurable', false) method() {}
}
}, msg);
assert.throws(() => {
class Foo {
@set('value', (x) => x) @set('configurable', false) method() {}
}
}, msg);
assert.doesNotThrow(() => {
class Foo {
@set('configurable', true) method1() {}
@set('writable', true) method2() {}
@set('enumerable', false) method3() {}
}
}, msg);
ProTip! Use n and p to navigate between commits in a pull request.