Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolo-ribaudo committed May 30, 2018
1 parent 784958c commit 2026871
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 24 deletions.
11 changes: 5 additions & 6 deletions packages/babel-plugin-proposal-decorators/src/index.js
Expand Up @@ -6,16 +6,12 @@ import legacyVisitor from "./transformer-legacy";
export default declare((api, options) => {
api.assertVersion(7);

const {
legacy = false,
decoratorsBeforeExport,
automaticParentheses,
} = options;

const { legacy = false } = options;
if (typeof legacy !== "boolean") {
throw new Error("'legacy' must be a boolean.");
}

let { decoratorsBeforeExport } = options;
if (decoratorsBeforeExport !== undefined) {
if (legacy) {
throw new Error(
Expand All @@ -25,8 +21,11 @@ export default declare((api, options) => {
if (typeof decoratorsBeforeExport !== "boolean") {
throw new Error("'decoratorsBeforeExport' must be a boolean.");
}
} else if (!legacy) {
decoratorsBeforeExport = true;
}

const { automaticParentheses } = options;
if (automaticParentheses !== undefined) {
if (legacy) {
throw new Error(
Expand Down
@@ -1 +1,2 @@
export default @dec() class {}
@dec()
export default class {}
8 changes: 0 additions & 8 deletions packages/babel-plugin-syntax-decorators/src/index.js
Expand Up @@ -8,14 +8,6 @@ export default declare((api, options) => {
throw new Error("'legacy' must be a boolean.");
}

if (legacy !== true) {
throw new Error(
"The new decorators proposal is not supported yet." +
' You must pass the `"legacy": true` option to' +
" @babel/plugin-syntax-decorators",
);
}

let { decoratorsBeforeExport } = options;
if (decoratorsBeforeExport !== undefined) {
if (legacy) {
Expand Down
13 changes: 4 additions & 9 deletions packages/babel-plugin-syntax-decorators/test/index.js
Expand Up @@ -15,25 +15,21 @@ describe("'legacy' option", function() {
expect(makeParser("", { legacy: "legacy" })).toThrow();
});

test.skip("'legacy': false", function() {
test("'legacy': false", function() {
expect(makeParser("({ @dec fn() {} })", { legacy: false })).toThrow();
});

test("'legacy': true", function() {
expect(makeParser("({ @dec fn() {} })", { legacy: true })).not.toThrow();
});

test.skip("defaults to 'false'", function() {
test("defaults to 'false'", function() {
expect(makeParser("({ @dec fn() {} })", {})).toThrow();
});

test("it must be true", function() {
expect(makeParser("", { legacy: false })).toThrow();
});
});

describe("'decoratorsBeforeExport' option", function() {
test.skip("must be boolean", function() {
test("must be boolean", function() {
expect(makeParser("", { decoratorsBeforeExport: "before" })).toThrow();
});

Expand All @@ -46,7 +42,6 @@ describe("'decoratorsBeforeExport' option", function() {
const BEFORE = "@dec export class Foo {}";
const AFTER = "export @dec class Foo {}";

// These are skipped
run(BEFORE, undefined, false);
run(AFTER, undefined, true);
run(BEFORE, true, false);
Expand All @@ -61,7 +56,7 @@ describe("'decoratorsBeforeExport' option", function() {
(code === BEFORE ? "before" : "after") +
"export";

test.skip(name, function() {
test(name, function() {
const expectTheParser = expect(
makeParser(code, { decoratorsBeforeExport: before }),
);
Expand Down
6 changes: 6 additions & 0 deletions packages/babel-types/src/asserts/generated/index.js
Expand Up @@ -468,6 +468,12 @@ export function assertObjectTypeAnnotation(
): void {
assert("ObjectTypeAnnotation", node, opts);
}
export function assertObjectTypeInternalSlot(
node: Object,
opts?: Object = {},
): void {
assert("ObjectTypeInternalSlot", node, opts);
}
export function assertObjectTypeCallProperty(
node: Object,
opts?: Object = {},
Expand Down
4 changes: 4 additions & 0 deletions packages/babel-types/src/builders/generated/index.js
Expand Up @@ -429,6 +429,10 @@ export function ObjectTypeAnnotation(...args: Array<any>): Object {
return builder("ObjectTypeAnnotation", ...args);
}
export { ObjectTypeAnnotation as objectTypeAnnotation };
export function ObjectTypeInternalSlot(...args: Array<any>): Object {
return builder("ObjectTypeInternalSlot", ...args);
}
export { ObjectTypeInternalSlot as objectTypeInternalSlot };
export function ObjectTypeCallProperty(...args: Array<any>): Object {
return builder("ObjectTypeCallProperty", ...args);
}
Expand Down
16 changes: 16 additions & 0 deletions packages/babel-types/src/validators/generated/index.js
Expand Up @@ -1522,6 +1522,20 @@ export function isObjectTypeAnnotation(node: Object, opts?: Object): boolean {

return false;
}
export function isObjectTypeInternalSlot(node: Object, opts?: Object): boolean {
if (!node) return false;

const nodeType = node.type;
if (nodeType === "ObjectTypeInternalSlot") {
if (typeof opts === "undefined") {
return true;
} else {
return shallowEqual(node, opts);
}
}

return false;
}
export function isObjectTypeCallProperty(node: Object, opts?: Object): boolean {
if (!node) return false;

Expand Down Expand Up @@ -3659,6 +3673,7 @@ export function isUserWhitespacable(node: Object, opts?: Object): boolean {
nodeType === "UserWhitespacable" ||
"ObjectMethod" === nodeType ||
"ObjectProperty" === nodeType ||
"ObjectTypeInternalSlot" === nodeType ||
"ObjectTypeCallProperty" === nodeType ||
"ObjectTypeIndexer" === nodeType ||
"ObjectTypeProperty" === nodeType ||
Expand Down Expand Up @@ -3882,6 +3897,7 @@ export function isFlow(node: Object, opts?: Object): boolean {
"NumberLiteralTypeAnnotation" === nodeType ||
"NumberTypeAnnotation" === nodeType ||
"ObjectTypeAnnotation" === nodeType ||
"ObjectTypeInternalSlot" === nodeType ||
"ObjectTypeCallProperty" === nodeType ||
"ObjectTypeIndexer" === nodeType ||
"ObjectTypeProperty" === nodeType ||
Expand Down

0 comments on commit 2026871

Please sign in to comment.