diff --git a/packages/babel-plugin-transform-property-literals/__tests__/fixtures/computed-property/actual.js b/packages/babel-plugin-transform-property-literals/__tests__/fixtures/computed-property/actual.js new file mode 100644 index 000000000..631536b6d --- /dev/null +++ b/packages/babel-plugin-transform-property-literals/__tests__/fixtures/computed-property/actual.js @@ -0,0 +1,5 @@ +({ + [a]: null, + [ಠ_ಠ]: "foo", + ["ಠ_ಠ"]: "bar" +}); diff --git a/packages/babel-plugin-transform-property-literals/__tests__/fixtures/computed-property/expected.js b/packages/babel-plugin-transform-property-literals/__tests__/fixtures/computed-property/expected.js new file mode 100644 index 000000000..e2a9c50a2 --- /dev/null +++ b/packages/babel-plugin-transform-property-literals/__tests__/fixtures/computed-property/expected.js @@ -0,0 +1,5 @@ +({ + [a]: null, + [ಠ_ಠ]: "foo", + ಠ_ಠ: "bar" +}); \ No newline at end of file diff --git a/packages/babel-plugin-transform-property-literals/__tests__/fixtures/es5-unicode-property/actual.js b/packages/babel-plugin-transform-property-literals/__tests__/fixtures/es5-unicode-property/actual.js new file mode 100644 index 000000000..71623bb19 --- /dev/null +++ b/packages/babel-plugin-transform-property-literals/__tests__/fixtures/es5-unicode-property/actual.js @@ -0,0 +1,9 @@ +// FIXME: The test name states that the property names should be transformed, +// but the `12e34` one isn’t transformed in the test + +// prettier-ignore +({ + "ಠ_ಠ": "bar", + "12e34": "wut", + "\u01FC": "AE" +}) diff --git a/packages/babel-plugin-transform-property-literals/__tests__/fixtures/es5-unicode-property/expected.js b/packages/babel-plugin-transform-property-literals/__tests__/fixtures/es5-unicode-property/expected.js new file mode 100644 index 000000000..822cd5577 --- /dev/null +++ b/packages/babel-plugin-transform-property-literals/__tests__/fixtures/es5-unicode-property/expected.js @@ -0,0 +1,9 @@ +// FIXME: The test name states that the property names should be transformed, +// but the `12e34` one isn’t transformed in the test + +// prettier-ignore +({ + ಠ_ಠ: "bar", + "12e34": "wut", + Ǽ: "AE" +}); \ No newline at end of file diff --git a/packages/babel-plugin-transform-property-literals/__tests__/fixtures/invalid-es5-property/actual.js b/packages/babel-plugin-transform-property-literals/__tests__/fixtures/invalid-es5-property/actual.js new file mode 100644 index 000000000..19dee5022 --- /dev/null +++ b/packages/babel-plugin-transform-property-literals/__tests__/fixtures/invalid-es5-property/actual.js @@ -0,0 +1,5 @@ +// prettier-ignore +({ + "\u2118": "wp", + "𐊧": "foo" +}); diff --git a/packages/babel-plugin-transform-property-literals/__tests__/fixtures/invalid-es5-property/expected.js b/packages/babel-plugin-transform-property-literals/__tests__/fixtures/invalid-es5-property/expected.js new file mode 100644 index 000000000..223d6422d --- /dev/null +++ b/packages/babel-plugin-transform-property-literals/__tests__/fixtures/invalid-es5-property/expected.js @@ -0,0 +1,5 @@ +// prettier-ignore +({ + "℘": "wp", + "𐊧": "foo" +}); \ No newline at end of file diff --git a/packages/babel-plugin-transform-property-literals/__tests__/fixtures/invalid-identifiers/actual.js b/packages/babel-plugin-transform-property-literals/__tests__/fixtures/invalid-identifiers/actual.js new file mode 100644 index 000000000..a5d14f441 --- /dev/null +++ b/packages/babel-plugin-transform-property-literals/__tests__/fixtures/invalid-identifiers/actual.js @@ -0,0 +1,7 @@ +// FIXME: The test name states that no transformation should take place, +// but the actual test specifies that the quotes should be stripped. +//prettier-ignore +({ + "default": null, + "import": null +}); diff --git a/packages/babel-plugin-transform-property-literals/__tests__/fixtures/invalid-identifiers/expected.js b/packages/babel-plugin-transform-property-literals/__tests__/fixtures/invalid-identifiers/expected.js new file mode 100644 index 000000000..14f4fcae2 --- /dev/null +++ b/packages/babel-plugin-transform-property-literals/__tests__/fixtures/invalid-identifiers/expected.js @@ -0,0 +1,7 @@ +// FIXME: The test name states that no transformation should take place, +// but the actual test specifies that the quotes should be stripped. +//prettier-ignore +({ + default: null, + import: null +}); \ No newline at end of file diff --git a/packages/babel-plugin-transform-property-literals/__tests__/fixtures/leading-zeros/actual.js b/packages/babel-plugin-transform-property-literals/__tests__/fixtures/leading-zeros/actual.js new file mode 100644 index 000000000..1808fe86f --- /dev/null +++ b/packages/babel-plugin-transform-property-literals/__tests__/fixtures/leading-zeros/actual.js @@ -0,0 +1,4 @@ +var data = { + "00": 1, + "01": 2 +}; diff --git a/packages/babel-plugin-transform-property-literals/__tests__/fixtures/leading-zeros/expected.js b/packages/babel-plugin-transform-property-literals/__tests__/fixtures/leading-zeros/expected.js new file mode 100644 index 000000000..a4c75a6f6 --- /dev/null +++ b/packages/babel-plugin-transform-property-literals/__tests__/fixtures/leading-zeros/expected.js @@ -0,0 +1,4 @@ +var data = { + "00": 1, + "01": 2 +}; \ No newline at end of file diff --git a/packages/babel-plugin-transform-property-literals/__tests__/fixtures/strip-quotes/actual.js b/packages/babel-plugin-transform-property-literals/__tests__/fixtures/strip-quotes/actual.js new file mode 100644 index 000000000..720b45e9f --- /dev/null +++ b/packages/babel-plugin-transform-property-literals/__tests__/fixtures/strip-quotes/actual.js @@ -0,0 +1,2 @@ +// prettier-ignore +var x = { "foo": "bar", "1": "baz", test: null }; diff --git a/packages/babel-plugin-transform-property-literals/__tests__/fixtures/strip-quotes/expected.js b/packages/babel-plugin-transform-property-literals/__tests__/fixtures/strip-quotes/expected.js new file mode 100644 index 000000000..13e7148e7 --- /dev/null +++ b/packages/babel-plugin-transform-property-literals/__tests__/fixtures/strip-quotes/expected.js @@ -0,0 +1,2 @@ +// prettier-ignore +var x = { foo: "bar", 1: "baz", test: null }; \ No newline at end of file diff --git a/packages/babel-plugin-transform-property-literals/__tests__/index.js b/packages/babel-plugin-transform-property-literals/__tests__/index.js new file mode 100644 index 000000000..d7c81a111 --- /dev/null +++ b/packages/babel-plugin-transform-property-literals/__tests__/index.js @@ -0,0 +1,2 @@ +const runner = require("test-runner"); +runner(__dirname); diff --git a/packages/babel-plugin-transform-property-literals/__tests__/transform-property-literals-test.js b/packages/babel-plugin-transform-property-literals/__tests__/transform-property-literals-test.js deleted file mode 100644 index fb6ada027..000000000 --- a/packages/babel-plugin-transform-property-literals/__tests__/transform-property-literals-test.js +++ /dev/null @@ -1,117 +0,0 @@ -jest.autoMockOff(); - -const thePlugin = require("test-transform")(require("../src/index")); - -describe("transform-property-literals-plugin", () => { - thePlugin( - "should strip unnecessary property literal qoutes", - ` - var x = { 'foo': 'bar' }; - `, - ` - var x = { foo: 'bar' }; - ` - ); - - thePlugin( - "should strip unnecessary property literal qoutes for numbers", - ` - var x = { '1': 'bar' }; - `, - ` - var x = { 1: 'bar' }; - ` - ); - - thePlugin( - "should not strip necessaary quotes for numbers with leading zeroes", - ` - var data = { - "00": 1, - "01": 2 - }; - ` - ); - - // FIXME: The test name states that no transformation should take place, - // but the actual test specifies that the quotes should be stripped. - thePlugin( - "should not transform invalid identifiers", - ` - ({ - "default": null, - "import": null - }); - `, - ` - ({ - default: null, - import: null - }); - ` - ); - - thePlugin( - "should not transform non-string properties", - ` - ({ - foo: null - }); - ` - ); - - thePlugin( - "should not transform propety keys that are computed", - ` - ({ - [a]: null - }); - ` - ); - - thePlugin( - "should not transform invalid es5 property names", - ` - ({ - "\u2118": "wp", - "𐊧": "foo" - }); - ` - ); - - // FIXME: The test name states that the property names should be transformed, - // but the `12e34` one isn’t transformed in the test - thePlugin( - "should transform valid ES5 unicodes as property names", - ` - ({ - "ಠ_ಠ": "bar", - "12e34": "wut", - "\u01FC": "AE" - }) - `, - ` - ({ - ಠ_ಠ: "bar", - "12e34": "wut", - \u01FC: "AE" - }); - ` - ); - - thePlugin( - "should transform computed properties which are strings", - ` - ({ - [ಠ_ಠ]: "foo", - ["ಠ_ಠ"]: "bar" - }); - `, - ` - ({ - [ಠ_ಠ]: "foo", - ಠ_ಠ: "bar" - }); - ` - ); -});