diff --git a/index.js b/index.js index bd1296a2f..8fc86a561 100644 --- a/index.js +++ b/index.js @@ -18,9 +18,15 @@ function guessLineEnding(text) { } function parse(text, opts) { - const parseFunction = opts.parser === "flow" - ? parser.parseWithFlow - : parser.parseWithBabylon; + let parseFunction; + + if (opts.parser === 'flow') { + parseFunction = parser.parseWithFlow; + } else if (opts.parser === 'typescript') { + parseFunction = parser.parseWithTypeScript; + } else { + parseFunction = parser.parseWithBabylon; + } try { return parseFunction(text); diff --git a/package.json b/package.json index c2dbb1c01..af9334c90 100644 --- a/package.json +++ b/package.json @@ -35,7 +35,9 @@ "rollup-plugin-json": "2.1.0", "rollup-plugin-node-builtins": "2.0.0", "rollup-plugin-node-globals": "1.1.0", - "rollup-plugin-node-resolve": "2.0.0" + "rollup-plugin-node-resolve": "2.0.0", + "typescript": "2.2.1", + "typescript-eslint-parser": "git://github.com/eslint/typescript-eslint-parser.git#215a012ec4d272939fa5a57d0231d22fb7f7a9e0" }, "scripts": { "test": "jest", diff --git a/src/parser.js b/src/parser.js index 64c730a77..200a1f5e5 100644 --- a/src/parser.js +++ b/src/parser.js @@ -54,4 +54,17 @@ function parseWithBabylon(text) { }); } -module.exports = { parseWithFlow, parseWithBabylon }; +function parseWithTypeScript(text) { + const parser = require('typescript-eslint-parser') + return parser.parse(text, { + loc: true, + range: true, + tokens: true, + attachComment: true, + ecmaFeatures: { + jsx: true, + } + }) +} + +module.exports = { parseWithFlow, parseWithBabylon, parseWithTypeScript }; diff --git a/tests/array_spread/__snapshots__/jsfmt.spec.js.snap b/tests/array_spread/__snapshots__/jsfmt.spec.js.snap index 40037c63f..3ec2ed4d2 100644 --- a/tests/array_spread/__snapshots__/jsfmt.spec.js.snap +++ b/tests/array_spread/__snapshots__/jsfmt.spec.js.snap @@ -8,3 +8,12 @@ exports[`multiple.js 1`] = ` [...a, ...b]; " `; + +exports[`multiple.js 2`] = ` +"[...a, ...b,]; +[...a, ...b]; +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +[...a, ...b]; +[...a, ...b]; +" +`; diff --git a/tests/array_spread/jsfmt.spec.js b/tests/array_spread/jsfmt.spec.js index 989047bcc..e98b84204 100644 --- a/tests/array_spread/jsfmt.spec.js +++ b/tests/array_spread/jsfmt.spec.js @@ -1 +1,2 @@ run_spec(__dirname); +run_spec(__dirname, {parser: 'typescript'}); diff --git a/tests/arrays/__snapshots__/jsfmt.spec.js.snap b/tests/arrays/__snapshots__/jsfmt.spec.js.snap index a999aea07..5c9618de2 100644 --- a/tests/arrays/__snapshots__/jsfmt.spec.js.snap +++ b/tests/arrays/__snapshots__/jsfmt.spec.js.snap @@ -13,6 +13,19 @@ exports[`last.js 1`] = ` " `; +exports[`last.js 2`] = ` +"[,]; +[,,]; +[,,1,]; +[,,1,1]; +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +[,]; +[, ,]; +[, , 1]; +[, , 1, 1]; +" +`; + exports[`preserve_empty_lines.js 1`] = ` "a = [ @@ -30,3 +43,21 @@ exports[`preserve_empty_lines.js 1`] = ` a = [1, 2, 3, 4]; " `; + +exports[`preserve_empty_lines.js 2`] = ` +"a = [ + + 1, + 2, + + 3, + + + 4, + + +] +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +a = [1, 2, 3, 4]; +" +`; diff --git a/tests/arrays/jsfmt.spec.js b/tests/arrays/jsfmt.spec.js index 989047bcc..1161d7bfb 100644 --- a/tests/arrays/jsfmt.spec.js +++ b/tests/arrays/jsfmt.spec.js @@ -1 +1,2 @@ run_spec(__dirname); +run_spec(__dirname, {parser: 'typescript'}); \ No newline at end of file diff --git a/tests/assignment_comments/__snapshots__/jsfmt.spec.js.snap b/tests/assignment_comments/__snapshots__/jsfmt.spec.js.snap index eda7518c9..a876a6ca1 100644 --- a/tests/assignment_comments/__snapshots__/jsfmt.spec.js.snap +++ b/tests/assignment_comments/__snapshots__/jsfmt.spec.js.snap @@ -88,3 +88,92 @@ var fnString = // Comment var fnString = \\"some\\" + \\"long\\" + \\"string\\"; // Comment " `; + +exports[`assignment_comments.js 2`] = ` +"fnString = + // Comment + 'some' + 'long' + 'string'; + +var fnString = + // Comment + 'some' + 'long' + 'string'; + +var fnString = + // Comment + + 'some' + 'long' + 'string'; + +var fnString = + + // Comment + + 'some' + 'long' + 'string'; + +var fnString = + /* comment */ + 'some' + 'long' + 'string'; + +var fnString = + /** + * multi-line + */ + 'some' + 'long' + 'string'; + +var fnString = + /* inline */ 'some' + 'long' + 'string' + 'some' + 'long' + 'string' + 'some' + 'long' + 'string' + 'some' + 'long' + 'string'; + +var fnString = // Comment + // Comment + 'some' + 'long' + 'string'; + +var fnString = // Comment + 'some' + 'long' + 'string'; +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +fnString = + // Comment + \\"some\\" + \\"long\\" + \\"string\\"; + +var fnString = + // Comment + \\"some\\" + \\"long\\" + \\"string\\"; + +var fnString = + // Comment + + \\"some\\" + \\"long\\" + \\"string\\"; + +var fnString = + // Comment + + \\"some\\" + \\"long\\" + \\"string\\"; + +var fnString = + /* comment */ + \\"some\\" + \\"long\\" + \\"string\\"; + +var fnString = + /** + * multi-line + */ + \\"some\\" + \\"long\\" + \\"string\\"; + +var fnString = /* inline */ \\"some\\" + + \\"long\\" + + \\"string\\" + + \\"some\\" + + \\"long\\" + + \\"string\\" + + \\"some\\" + + \\"long\\" + + \\"string\\" + + \\"some\\" + + \\"long\\" + + \\"string\\"; + +var fnString = // Comment + // Comment + \\"some\\" + \\"long\\" + \\"string\\"; + +var fnString = \\"some\\" + \\"long\\" + \\"string\\"; // Comment +" +`; diff --git a/tests/assignment_comments/jsfmt.spec.js b/tests/assignment_comments/jsfmt.spec.js index 989047bcc..1161d7bfb 100644 --- a/tests/assignment_comments/jsfmt.spec.js +++ b/tests/assignment_comments/jsfmt.spec.js @@ -1 +1,2 @@ run_spec(__dirname); +run_spec(__dirname, {parser: 'typescript'}); \ No newline at end of file diff --git a/tests/async/__snapshots__/jsfmt.spec.js.snap b/tests/async/__snapshots__/jsfmt.spec.js.snap index 4ec14ed9e..01749e485 100644 --- a/tests/async/__snapshots__/jsfmt.spec.js.snap +++ b/tests/async/__snapshots__/jsfmt.spec.js.snap @@ -29,6 +29,35 @@ async function f() { " `; +exports[`await_parse.js 2`] = ` +"async function f() { (await f()).length } +async function g() { + invariant( + (await driver.navigator.getUrl()).substr(-7) + ); +} +function *f(){ + !(yield a); +} +async function f() { + a = !(await f()); +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +async function f() { + (await f()).length; +} +async function g() { + invariant((await driver.navigator.getUrl()).substr(-7)); +} +function* f() { + !(yield a); +} +async function f() { + a = !await f(); +} +" +`; + exports[`conditional-expression.js 1`] = ` "async function f() { const result = typeof fn === 'function' ? await fn() : null; @@ -49,3 +78,24 @@ async function f() { })(); " `; + +exports[`conditional-expression.js 2`] = ` +"async function f() { + const result = typeof fn === 'function' ? await fn() : null; +} + +(async function() { + console.log( + await (true ? Promise.resolve(\\"A\\") : Promise.resolve(\\"B\\")) + ); +})() +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +async function f() { + const result = typeof fn === \\"function\\" ? await fn() : null; +} + +(async function() { + console.log(await (true ? Promise.resolve(\\"A\\") : Promise.resolve(\\"B\\"))); +})(); +" +`; diff --git a/tests/async/jsfmt.spec.js b/tests/async/jsfmt.spec.js index 989047bcc..e98b84204 100644 --- a/tests/async/jsfmt.spec.js +++ b/tests/async/jsfmt.spec.js @@ -1 +1,2 @@ run_spec(__dirname); +run_spec(__dirname, {parser: 'typescript'}); diff --git a/tests/bracketSpacing/__snapshots__/jsfmt.spec.js.snap b/tests/bracketSpacing/__snapshots__/jsfmt.spec.js.snap index be1f1b9e5..a5546b251 100644 --- a/tests/bracketSpacing/__snapshots__/jsfmt.spec.js.snap +++ b/tests/bracketSpacing/__snapshots__/jsfmt.spec.js.snap @@ -18,6 +18,24 @@ const arr2 = [1, 2, 3, 4]; " `; +exports[`array.js 3`] = ` +"const arr1 = [1,2,3,4]; +const arr2 = [1, 2, 3, 4]; +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +const arr1 = [1, 2, 3, 4]; +const arr2 = [1, 2, 3, 4]; +" +`; + +exports[`array.js 4`] = ` +"const arr1 = [1,2,3,4]; +const arr2 = [1, 2, 3, 4]; +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +const arr1 = [1, 2, 3, 4]; +const arr2 = [1, 2, 3, 4]; +" +`; + exports[`object.js 1`] = ` "const obj1 = {a:1, b:2, c:3} const obj2 = { a:1, b:2, c:3 }; @@ -35,3 +53,21 @@ const obj1 = {a: 1, b: 2, c: 3}; const obj2 = {a: 1, b: 2, c: 3}; " `; + +exports[`object.js 3`] = ` +"const obj1 = {a:1, b:2, c:3} +const obj2 = { a:1, b:2, c:3 }; +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +const obj1 = { a: 1, b: 2, c: 3 }; +const obj2 = { a: 1, b: 2, c: 3 }; +" +`; + +exports[`object.js 4`] = ` +"const obj1 = {a:1, b:2, c:3} +const obj2 = { a:1, b:2, c:3 }; +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +const obj1 = {a: 1, b: 2, c: 3}; +const obj2 = {a: 1, b: 2, c: 3}; +" +`; diff --git a/tests/bracketSpacing/jsfmt.spec.js b/tests/bracketSpacing/jsfmt.spec.js index 7d17b3723..ee11f0138 100644 --- a/tests/bracketSpacing/jsfmt.spec.js +++ b/tests/bracketSpacing/jsfmt.spec.js @@ -1,3 +1,5 @@ run_spec(__dirname); - run_spec(__dirname, { bracketSpacing: false }); + +run_spec(__dirname, {parser: 'typescript'}); +run_spec(__dirname, { parser: 'typescript', bracketSpacing: false }); \ No newline at end of file diff --git a/tests/break-calls/__snapshots__/jsfmt.spec.js.snap b/tests/break-calls/__snapshots__/jsfmt.spec.js.snap index a8a0bc087..a270452d6 100644 --- a/tests/break-calls/__snapshots__/jsfmt.spec.js.snap +++ b/tests/break-calls/__snapshots__/jsfmt.spec.js.snap @@ -79,3 +79,83 @@ expect( ).toEqualAtomLongLongLongLongRange(new LongLongLongRange([0, 0], [0, 0])); " `; + +exports[`break.js 2`] = ` +"h(f(g(() => { + a +}))) + +deepCopyAndAsyncMapLeavesA( + { source: sourceValue, destination: destination[sourceKey] }, + { valueMapper, overwriteExistingKeys } +) + +deepCopyAndAsyncMapLeavesB( + 1337, + { source: sourceValue, destination: destination[sourceKey] }, + { valueMapper, overwriteExistingKeys } +) + +deepCopyAndAsyncMapLeavesC( + { source: sourceValue, destination: destination[sourceKey] }, + 1337, + { valueMapper, overwriteExistingKeys } +) + +function someFunction(url) { + return get(url) + .then( + json => dispatch(success(json)), + error => dispatch(failed(error)) + ); +} + +const mapChargeItems = fp.flow( + l => l < 10 ? l: 1, + l => Immutable.Range(l).toMap() +); + +expect(new LongLongLongLongLongRange([0, 0], [0, 0])).toEqualAtomLongLongLongLongRange(new LongLongLongRange([0, 0], [0, 0])); +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +h( + f( + g(() => { + a; + }) + ) +); + +deepCopyAndAsyncMapLeavesA( + { source: sourceValue, destination: destination[sourceKey] }, + { valueMapper, overwriteExistingKeys } +); + +deepCopyAndAsyncMapLeavesB( + 1337, + { source: sourceValue, destination: destination[sourceKey] }, + { valueMapper, overwriteExistingKeys } +); + +deepCopyAndAsyncMapLeavesC( + { source: sourceValue, destination: destination[sourceKey] }, + 1337, + { valueMapper, overwriteExistingKeys } +); + +function someFunction(url) { + return get(url).then( + json => dispatch(success(json)), + error => dispatch(failed(error)) + ); +} + +const mapChargeItems = fp.flow( + l => l < 10 ? l : 1, + l => Immutable.Range(l).toMap() +); + +expect( + new LongLongLongLongLongRange([0, 0], [0, 0]) +).toEqualAtomLongLongLongLongRange(new LongLongLongRange([0, 0], [0, 0])); +" +`; diff --git a/tests/break-calls/jsfmt.spec.js b/tests/break-calls/jsfmt.spec.js index 989047bcc..1161d7bfb 100644 --- a/tests/break-calls/jsfmt.spec.js +++ b/tests/break-calls/jsfmt.spec.js @@ -1 +1,2 @@ run_spec(__dirname); +run_spec(__dirname, {parser: 'typescript'}); \ No newline at end of file diff --git a/tests/class_comment/__snapshots__/jsfmt.spec.js.snap b/tests/class_comment/__snapshots__/jsfmt.spec.js.snap index 0fb2c394f..1ba9b5e19 100644 --- a/tests/class_comment/__snapshots__/jsfmt.spec.js.snap +++ b/tests/class_comment/__snapshots__/jsfmt.spec.js.snap @@ -56,3 +56,60 @@ class A extends /* a */ B {} (class A extends /* a */ B {}); " `; + +exports[`comments.js 2`] = ` +"class A // comment 1 + // comment 2 + extends B {} + +class A extends B // comment1 +// comment2 +// comment3 +{} + +class A /* a */ extends B {} +class A extends B /* a */ {} +class A extends /* a */ B {} + +(class A // comment 1 + // comment 2 + extends B {}); + +(class A extends B // comment1 +// comment2 +// comment3 +{}); + +(class A /* a */ extends B {}); +(class A extends B /* a */ {}); +(class A extends /* a */ B {}); +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +// comment 1 +// comment 2 +class A extends B {} + +// comment1 +// comment2 +// comment3 +class A extends B {} + +class A /* a */ extends B {} +class A extends B /* a */ { +} +class A extends /* a */ B {} + +// comment 1 +// comment 2 +(class A extends B {}); + +// comment1 +// comment2 +// comment3 +(class A extends B {}); + +(class A /* a */ extends B {}); +(class A extends B /* a */ { +}); +(class A extends /* a */ B {}); +" +`; diff --git a/tests/class_comment/jsfmt.spec.js b/tests/class_comment/jsfmt.spec.js index 989047bcc..1161d7bfb 100644 --- a/tests/class_comment/jsfmt.spec.js +++ b/tests/class_comment/jsfmt.spec.js @@ -1 +1,2 @@ run_spec(__dirname); +run_spec(__dirname, {parser: 'typescript'}); \ No newline at end of file diff --git a/tests/class_extends/__snapshots__/jsfmt.spec.js.snap b/tests/class_extends/__snapshots__/jsfmt.spec.js.snap index 5e48be6d2..5713ceea5 100644 --- a/tests/class_extends/__snapshots__/jsfmt.spec.js.snap +++ b/tests/class_extends/__snapshots__/jsfmt.spec.js.snap @@ -118,3 +118,122 @@ function* f() { x = class extends (++b) {}; " `; + +exports[`extends.js 2`] = ` +"// \\"ArrowFunctionExpression\\" +class a extends (() => {}) {} + +// \\"AssignmentExpression\\" +class a extends (b = c) {} + +// \\"AwaitExpression\\" +async function f() { + class a extends (await b) {} +} + +// \\"BinaryExpression\\" +class a extends (b + c) {} + +// \\"CallExpression\\" +class a extends b() {} + +// \\"ClassExpression\\" +class a extends class {} {} + +// \\"ConditionalExpression\\" +class a extends (b ? c : d) {} + +// \\"FunctionExpression\\" +class a extends (function() {}) {} + +// \\"LogicalExpression\\" +class a extends (b || c) {} + +// \\"MemberExpression\\" +class a extends b.c {} + +// \\"NewExpression\\" +class a extends (new B()) {} + +// \\"ObjectExpression\\" +class a extends ({}) {} + +// \\"SequenceExpression\\" +class a extends (b, c) {} + +// \\"TaggedTemplateExpression\\" +class a extends \`\` {} + +// \\"UnaryExpression\\" +class a extends (void b) {} + +// \\"UpdateExpression\\" +class a extends (++b) {} + +// \\"YieldExpression\\" +function* f() { + // Flow has a bug parsing it. + // class a extends (yield 1) {} +} + +x = class extends (++b) {} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +// \\"ArrowFunctionExpression\\" +class a extends (() => {}) {} + +// \\"AssignmentExpression\\" +class a extends (b = c) {} + +// \\"AwaitExpression\\" +async function f() { + class a extends (await b) {} +} + +// \\"BinaryExpression\\" +class a extends (b + c) {} + +// \\"CallExpression\\" +class a extends b() {} + +// \\"ClassExpression\\" +class a extends class {} {} + +// \\"ConditionalExpression\\" +class a extends (b ? c : d) {} + +// \\"FunctionExpression\\" +class a extends function() {} {} + +// \\"LogicalExpression\\" +class a extends (b || c) {} + +// \\"MemberExpression\\" +class a extends b.c {} + +// \\"NewExpression\\" +class a extends (new B()) {} + +// \\"ObjectExpression\\" +class a extends ({}) {} + +// \\"SequenceExpression\\" +class a extends (b, c) {} + +// \\"TaggedTemplateExpression\\" +class a extends \`\` {} + +// \\"UnaryExpression\\" +class a extends (void b) {} + +// \\"UpdateExpression\\" +class a extends (++b) {} + +// \\"YieldExpression\\" +function* f() { + // Flow has a bug parsing it. + // class a extends (yield 1) {} +} + +x = class extends (++b) {}; +" +`; diff --git a/tests/class_extends/jsfmt.spec.js b/tests/class_extends/jsfmt.spec.js index 989047bcc..1161d7bfb 100644 --- a/tests/class_extends/jsfmt.spec.js +++ b/tests/class_extends/jsfmt.spec.js @@ -1 +1,2 @@ run_spec(__dirname); +run_spec(__dirname, {parser: 'typescript'}); \ No newline at end of file diff --git a/tests/computed_props/__snapshots__/jsfmt.spec.js.snap b/tests/computed_props/__snapshots__/jsfmt.spec.js.snap index fafd502e9..ee18c93da 100644 --- a/tests/computed_props/__snapshots__/jsfmt.spec.js.snap +++ b/tests/computed_props/__snapshots__/jsfmt.spec.js.snap @@ -10,3 +10,14 @@ class c { } " `; + +exports[`classes.js 2`] = ` +"class c { + [\\"i\\"]() {} +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +class c { + [\\"i\\"]() {} +} +" +`; diff --git a/tests/computed_props/jsfmt.spec.js b/tests/computed_props/jsfmt.spec.js index 989047bcc..e98b84204 100644 --- a/tests/computed_props/jsfmt.spec.js +++ b/tests/computed_props/jsfmt.spec.js @@ -1 +1,2 @@ run_spec(__dirname); +run_spec(__dirname, {parser: 'typescript'}); diff --git a/tests/conditional/__snapshots__/jsfmt.spec.js.snap b/tests/conditional/__snapshots__/jsfmt.spec.js.snap index bce41884e..4bebfd114 100644 --- a/tests/conditional/__snapshots__/jsfmt.spec.js.snap +++ b/tests/conditional/__snapshots__/jsfmt.spec.js.snap @@ -79,6 +79,85 @@ const { configureStore } = process.env.NODE_ENV === \\"production\\" " `; +exports[`comments.js 2`] = ` +"var inspect = 4 === util.inspect.length + ? // node <= 0.8.x + (function(v, colors) { + return util.inspect(v, void 0, void 0, colors); + }) + : // node > 0.8.x + (function(v, colors) { + return util.inspect(v, { colors: colors }); + }); + +var inspect = 4 === util.inspect.length + ? // node <= 0.8.x + (function(v, colors) { + return util.inspect(v, void 0, void 0, colors); + }) + : // node > 0.8.x + (function(v, colors) { + return util.inspect(v, { colors: colors }); + }); + +const extractTextPluginOptions = shouldUseRelativeAssetPaths + // Making sure that the publicPath goes back to to build folder. + ? { publicPath: Array(cssFilename.split('/').length).join('../') } : + {}; + +const extractTextPluginOptions = shouldUseRelativeAssetPaths + ? // Making sure that the publicPath goes back to to build folder. + { publicPath: Array(cssFilename.split(\\"/\\").length).join(\\"../\\") } + : {}; + +const extractTextPluginOptions = shouldUseRelativeAssetPaths // Making sure that the publicPath goes back to to build folder. + ? { publicPath: Array(cssFilename.split(\\"/\\").length).join(\\"../\\") } + : {}; + +const { configureStore } = process.env.NODE_ENV === \\"production\\" + ? require(\\"./configureProdStore\\") // a + : require(\\"./configureDevStore\\"); // b +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +var inspect = 4 === util.inspect.length + ? // node <= 0.8.x + function(v, colors) { + return util.inspect(v, void 0, void 0, colors); + } + : // node > 0.8.x + function(v, colors) { + return util.inspect(v, { colors: colors }); + }; + +var inspect = 4 === util.inspect.length + ? // node <= 0.8.x + function(v, colors) { + return util.inspect(v, void 0, void 0, colors); + } + : // node > 0.8.x + function(v, colors) { + return util.inspect(v, { colors: colors }); + }; + +const extractTextPluginOptions = shouldUseRelativeAssetPaths + ? // Making sure that the publicPath goes back to to build folder. + { publicPath: Array(cssFilename.split(\\"/\\").length).join(\\"../\\") } + : {}; + +const extractTextPluginOptions = shouldUseRelativeAssetPaths + ? // Making sure that the publicPath goes back to to build folder. + { publicPath: Array(cssFilename.split(\\"/\\").length).join(\\"../\\") } + : {}; + +const extractTextPluginOptions = shouldUseRelativeAssetPaths // Making sure that the publicPath goes back to to build folder. + ? { publicPath: Array(cssFilename.split(\\"/\\").length).join(\\"../\\") } + : {}; + +const { configureStore } = process.env.NODE_ENV === \\"production\\" + ? require(\\"./configureProdStore\\") // a + : require(\\"./configureDevStore\\"); // b +" +`; + exports[`new-expression.js 1`] = ` "const testConsole = new TestConsole( config.useStderr ? process.stderr : process.stdout @@ -89,3 +168,14 @@ const testConsole = new TestConsole( ); " `; + +exports[`new-expression.js 2`] = ` +"const testConsole = new TestConsole( + config.useStderr ? process.stderr : process.stdout +); +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +const testConsole = new TestConsole( + config.useStderr ? process.stderr : process.stdout +); +" +`; diff --git a/tests/conditional/jsfmt.spec.js b/tests/conditional/jsfmt.spec.js index 989047bcc..e98b84204 100644 --- a/tests/conditional/jsfmt.spec.js +++ b/tests/conditional/jsfmt.spec.js @@ -1 +1,2 @@ run_spec(__dirname); +run_spec(__dirname, {parser: 'typescript'}); diff --git a/tests/directives/__snapshots__/jsfmt.spec.js.snap b/tests/directives/__snapshots__/jsfmt.spec.js.snap index a64602510..3a93b3aa9 100644 --- a/tests/directives/__snapshots__/jsfmt.spec.js.snap +++ b/tests/directives/__snapshots__/jsfmt.spec.js.snap @@ -12,6 +12,12 @@ exports[`last-line-0.js 2`] = ` " `; +exports[`last-line-0.js 3`] = ` +"'use strict';~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +\\"use strict\\"; +" +`; + exports[`last-line-1.js 1`] = ` "'use strict'; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -26,6 +32,13 @@ exports[`last-line-1.js 2`] = ` " `; +exports[`last-line-1.js 3`] = ` +"'use strict'; +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +\\"use strict\\"; +" +`; + exports[`last-line-2.js 1`] = ` "'use strict'; @@ -42,6 +55,14 @@ exports[`last-line-2.js 2`] = ` " `; +exports[`last-line-2.js 3`] = ` +"'use strict'; + +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +\\"use strict\\"; +" +`; + exports[`newline.js 1`] = ` "/* @flow */ @@ -80,6 +101,25 @@ a(); " `; +exports[`newline.js 3`] = ` +"/* @flow */ + +\\"use strict\\"; + +import a from \\"a\\"; + +a(); +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +/* @flow */ + +\\"use strict\\"; + +import a from \\"a\\"; + +a(); +" +`; + exports[`no-newline.js 1`] = ` "\\"use strict\\"; a @@ -98,6 +138,15 @@ a; " `; +exports[`no-newline.js 3`] = ` +"\\"use strict\\"; +a +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +\\"use strict\\"; +a; +" +`; + exports[`test.js 1`] = ` "\\"use strict\\"; @@ -127,3 +176,18 @@ function fn() { } " `; + +exports[`test.js 3`] = ` +"\\"use strict\\"; + +function fn() { + \\"use strict\\"; +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +\\"use strict\\"; + +function fn() { + \\"use strict\\"; +} +" +`; diff --git a/tests/directives/jsfmt.spec.js b/tests/directives/jsfmt.spec.js index d5ec770a9..d6e0ca05a 100644 --- a/tests/directives/jsfmt.spec.js +++ b/tests/directives/jsfmt.spec.js @@ -1,2 +1,3 @@ run_spec(__dirname); +run_spec(__dirname, {parser: 'typescript'}); run_spec(__dirname, {parser: 'babylon'}); diff --git a/tests/empty_statement/__snapshots__/jsfmt.spec.js.snap b/tests/empty_statement/__snapshots__/jsfmt.spec.js.snap index 42e607bca..4e237c71b 100644 --- a/tests/empty_statement/__snapshots__/jsfmt.spec.js.snap +++ b/tests/empty_statement/__snapshots__/jsfmt.spec.js.snap @@ -21,3 +21,25 @@ do; while (1); " `; + +exports[`body.js 2`] = ` +"with (a); +if (1); else if (2); else; +for (;;); +while (1); +for (var i in o); +for (var i of o); +do; while(1); +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +with (a); +if (1); +else if (2); +else; +for (;;); +while (1); +for (var i in o); +for (var i of o); +do; +while (1); +" +`; diff --git a/tests/empty_statement/jsfmt.spec.js b/tests/empty_statement/jsfmt.spec.js index 989047bcc..1161d7bfb 100644 --- a/tests/empty_statement/jsfmt.spec.js +++ b/tests/empty_statement/jsfmt.spec.js @@ -1 +1,2 @@ run_spec(__dirname); +run_spec(__dirname, {parser: 'typescript'}); \ No newline at end of file diff --git a/tests/export/__snapshots__/jsfmt.spec.js.snap b/tests/export/__snapshots__/jsfmt.spec.js.snap index 560bd6874..3b651180e 100644 --- a/tests/export/__snapshots__/jsfmt.spec.js.snap +++ b/tests/export/__snapshots__/jsfmt.spec.js.snap @@ -54,6 +54,60 @@ export {fitsIn, oneLine}; " `; +exports[`bracket.js 3`] = ` +"export { + runTaskForChanged, + description, + someOtherLabel, + thatMakes, + itGo, + multiLine, + andMore, + soWeCanGetItTo80Columns +}; +export {fitsIn, oneLine}; +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +export { + runTaskForChanged, + description, + someOtherLabel, + thatMakes, + itGo, + multiLine, + andMore, + soWeCanGetItTo80Columns +}; +export { fitsIn, oneLine }; +" +`; + +exports[`bracket.js 4`] = ` +"export { + runTaskForChanged, + description, + someOtherLabel, + thatMakes, + itGo, + multiLine, + andMore, + soWeCanGetItTo80Columns +}; +export {fitsIn, oneLine}; +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +export { + runTaskForChanged, + description, + someOtherLabel, + thatMakes, + itGo, + multiLine, + andMore, + soWeCanGetItTo80Columns +}; +export {fitsIn, oneLine}; +" +`; + exports[`empty.js 1`] = ` "export {}; export {} from \\".\\"; @@ -71,3 +125,21 @@ export {}; export {} from \\".\\"; " `; + +exports[`empty.js 3`] = ` +"export {}; +export {} from \\".\\"; +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +export {}; +export {} from \\".\\"; +" +`; + +exports[`empty.js 4`] = ` +"export {}; +export {} from \\".\\"; +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +export {}; +export {} from \\".\\"; +" +`; diff --git a/tests/export/jsfmt.spec.js b/tests/export/jsfmt.spec.js index 7e2f65bc9..6bf31d0c1 100644 --- a/tests/export/jsfmt.spec.js +++ b/tests/export/jsfmt.spec.js @@ -1,2 +1,5 @@ run_spec(__dirname); run_spec(__dirname, {bracketSpacing: false}); + +run_spec(__dirname, {parser: 'typescript'}); +run_spec(__dirname, {parser: 'typescript', bracketSpacing: false}); \ No newline at end of file diff --git a/tests/export_default/__snapshots__/jsfmt.spec.js.snap b/tests/export_default/__snapshots__/jsfmt.spec.js.snap index 27dbfe849..d54eaf6dc 100644 --- a/tests/export_default/__snapshots__/jsfmt.spec.js.snap +++ b/tests/export_default/__snapshots__/jsfmt.spec.js.snap @@ -6,3 +6,10 @@ exports[`body.js 1`] = ` export default (class {}[1] = 1); " `; + +exports[`body.js 2`] = ` +"export default (class {}[1] = 1); +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +export default (class {}[1] = 1); +" +`; diff --git a/tests/export_default/jsfmt.spec.js b/tests/export_default/jsfmt.spec.js index 989047bcc..1161d7bfb 100644 --- a/tests/export_default/jsfmt.spec.js +++ b/tests/export_default/jsfmt.spec.js @@ -1 +1,2 @@ run_spec(__dirname); +run_spec(__dirname, {parser: 'typescript'}); \ No newline at end of file diff --git a/tests/exports/__snapshots__/jsfmt.spec.js.snap b/tests/exports/__snapshots__/jsfmt.spec.js.snap index 5f7830c60..d5339089b 100644 --- a/tests/exports/__snapshots__/jsfmt.spec.js.snap +++ b/tests/exports/__snapshots__/jsfmt.spec.js.snap @@ -12,3 +12,16 @@ export { } from \\"exports\\"; " `; + +exports[`test.js 2`] = ` +"export { value1, value2 as value2_renamed, value3, value4 as value4_renamed, value5 } from \\"exports\\"; +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +export { + value1, + value2 as value2_renamed, + value3, + value4 as value4_renamed, + value5 +} from \\"exports\\"; +" +`; diff --git a/tests/exports/jsfmt.spec.js b/tests/exports/jsfmt.spec.js index 989047bcc..1161d7bfb 100644 --- a/tests/exports/jsfmt.spec.js +++ b/tests/exports/jsfmt.spec.js @@ -1 +1,2 @@ run_spec(__dirname); +run_spec(__dirname, {parser: 'typescript'}); \ No newline at end of file diff --git a/tests/for/__snapshots__/jsfmt.spec.js.snap b/tests/for/__snapshots__/jsfmt.spec.js.snap index 50d9ae1a9..dc9e4f96d 100644 --- a/tests/for/__snapshots__/jsfmt.spec.js.snap +++ b/tests/for/__snapshots__/jsfmt.spec.js.snap @@ -11,6 +11,17 @@ for (var i = 0; i < 10; ++i) { " `; +exports[`for.js 2`] = ` +"for (;;) {} +for (var i = 0; i < 10; ++i) {} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +for (;;) { +} +for (var i = 0; i < 10; ++i) { +} +" +`; + exports[`in.js 1`] = ` "for ((x in a);;) {} for (a=(a in b);;) {} @@ -22,6 +33,17 @@ for (a = (a in b); ; ) { " `; +exports[`in.js 2`] = ` +"for ((x in a);;) {} +for (a=(a in b);;) {} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +for ((x in a); ; ) { +} +for (a = (a in b); ; ) { +} +" +`; + exports[`var.js 1`] = ` "for (a in b) var c = {}; []; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -30,3 +52,12 @@ for (a in b) []; " `; + +exports[`var.js 2`] = ` +"for (a in b) var c = {}; []; +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +for (a in b) + var c = {}; +[]; +" +`; diff --git a/tests/for/jsfmt.spec.js b/tests/for/jsfmt.spec.js index 989047bcc..e98b84204 100644 --- a/tests/for/jsfmt.spec.js +++ b/tests/for/jsfmt.spec.js @@ -1 +1,2 @@ run_spec(__dirname); +run_spec(__dirname, {parser: 'typescript'}); diff --git a/tests/function/__snapshots__/jsfmt.spec.js.snap b/tests/function/__snapshots__/jsfmt.spec.js.snap index 7c5a63a4f..e5d39150b 100644 --- a/tests/function/__snapshots__/jsfmt.spec.js.snap +++ b/tests/function/__snapshots__/jsfmt.spec.js.snap @@ -26,3 +26,30 @@ a + function() {}; new function() {}(); " `; + +exports[`function_expression.js 2`] = ` +"(function() {}).length +typeof (function() {}); +export default (function() {})(); +(function() {})()\`\`; +(function() {})\`\`; +new (function() {}); +(function() {}); +a = function f() {} || b; +(function() {} && a); +a + function() {}; +new function() {}; +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +(function() {}.length); +typeof function() {}; +export default (function() {})(); +(function() {})()\`\`; +(function() {})\`\`; +new function() {}(); +(function() {}); +a = function f() {} || b; +(function() {} && a); +a + function() {}; +new function() {}(); +" +`; diff --git a/tests/function/jsfmt.spec.js b/tests/function/jsfmt.spec.js index 989047bcc..1161d7bfb 100644 --- a/tests/function/jsfmt.spec.js +++ b/tests/function/jsfmt.spec.js @@ -1 +1,2 @@ run_spec(__dirname); +run_spec(__dirname, {parser: 'typescript'}); \ No newline at end of file diff --git a/tests/if_comments/__snapshots__/jsfmt.spec.js.snap b/tests/if_comments/__snapshots__/jsfmt.spec.js.snap index 96e8c1407..93274c62a 100644 --- a/tests/if_comments/__snapshots__/jsfmt.spec.js.snap +++ b/tests/if_comments/__snapshots__/jsfmt.spec.js.snap @@ -73,3 +73,77 @@ async function f() { } " `; + +exports[`if_comments.js 2`] = ` +"async function f() { + if (untrackedChoice === 0) /* Cancel */ { + return null; + } else if (untrackedChoice === 1) /* Add */ { + await repository.addAll(Array.from(untrackedChanges.keys())); + shouldAmend = true; + } else if (untrackedChoice === 2) /* Allow Untracked */ { + allowUntracked = true; + } +} + +async function f() { + if (untrackedChoice === 0) + /* Cancel */ { + return null; + } + else if (untrackedChoice === 1) + /* Add */ { + await repository.addAll(Array.from(untrackedChanges.keys())); + shouldAmend = true; + } + else if (untrackedChoice === 2) + /* Allow Untracked */ { + allowUntracked = true; + } +} + +async function f() { + if (untrackedChoice === 0) { + /* Cancel */ return null; + } else if (untrackedChoice === 1) { + /* Add */ await repository.addAll(Array.from(untrackedChanges.keys())); + shouldAmend = true; + } else if (untrackedChoice === 2) { + /* Allow Untracked */ allowUntracked = true; + } +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +async function f() { + if (untrackedChoice === 0) { + /* Cancel */ return null; + } else if (untrackedChoice === 1) { + /* Add */ await repository.addAll(Array.from(untrackedChanges.keys())); + shouldAmend = true; + } else if (untrackedChoice === 2) { + /* Allow Untracked */ allowUntracked = true; + } +} + +async function f() { + if (untrackedChoice === 0) { + /* Cancel */ return null; + } else if (untrackedChoice === 1) { + /* Add */ await repository.addAll(Array.from(untrackedChanges.keys())); + shouldAmend = true; + } else if (untrackedChoice === 2) { + /* Allow Untracked */ allowUntracked = true; + } +} + +async function f() { + if (untrackedChoice === 0) { + /* Cancel */ return null; + } else if (untrackedChoice === 1) { + /* Add */ await repository.addAll(Array.from(untrackedChanges.keys())); + shouldAmend = true; + } else if (untrackedChoice === 2) { + /* Allow Untracked */ allowUntracked = true; + } +} +" +`; diff --git a/tests/if_comments/jsfmt.spec.js b/tests/if_comments/jsfmt.spec.js index 989047bcc..1161d7bfb 100644 --- a/tests/if_comments/jsfmt.spec.js +++ b/tests/if_comments/jsfmt.spec.js @@ -1 +1,2 @@ run_spec(__dirname); +run_spec(__dirname, {parser: 'typescript'}); \ No newline at end of file diff --git a/tests/import/__snapshots__/jsfmt.spec.js.snap b/tests/import/__snapshots__/jsfmt.spec.js.snap index 7adcfa0a6..25ae675a3 100644 --- a/tests/import/__snapshots__/jsfmt.spec.js.snap +++ b/tests/import/__snapshots__/jsfmt.spec.js.snap @@ -54,6 +54,60 @@ import {fitsIn, oneLine} from \\".\\"; " `; +exports[`brackets.js 3`] = ` +"import { + runTaskForChanged, + description, + someOtherLabel, + thatMakes, + itGo, + multiLine, + andMore, + soWeCanGetItTo80Columns +} from '.'; +import {fitsIn, oneLine} from '.'; +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +import { + runTaskForChanged, + description, + someOtherLabel, + thatMakes, + itGo, + multiLine, + andMore, + soWeCanGetItTo80Columns +} from \\".\\"; +import { fitsIn, oneLine } from \\".\\"; +" +`; + +exports[`brackets.js 4`] = ` +"import { + runTaskForChanged, + description, + someOtherLabel, + thatMakes, + itGo, + multiLine, + andMore, + soWeCanGetItTo80Columns +} from '.'; +import {fitsIn, oneLine} from '.'; +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +import { + runTaskForChanged, + description, + someOtherLabel, + thatMakes, + itGo, + multiLine, + andMore, + soWeCanGetItTo80Columns +} from \\".\\"; +import {fitsIn, oneLine} from \\".\\"; +" +`; + exports[`comments.js 1`] = ` "import { a //comment1 //comment2 @@ -156,6 +210,108 @@ import { " `; +exports[`comments.js 3`] = ` +"import { a //comment1 +//comment2 +//comment3 +as b} from \\"\\"; + +import { + a as //comment1 + //comment2 + //comment3 + b +} from \\"\\"; + +import { + a as //comment2 //comment1 + //comment3 + b +} from \\"\\"; + +import { + a as //comment3 //comment2 //comment1 + b +} from \\"\\"; +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +import { + //comment1 + //comment2 + //comment3 + a as b +} from \\"\\"; + +import { + //comment1 + //comment2 + //comment3 + a as b +} from \\"\\"; + +import { + //comment2 //comment1 + //comment3 + a as b +} from \\"\\"; + +import { + //comment3 //comment2 //comment1 + a as b +} from \\"\\"; +" +`; + +exports[`comments.js 4`] = ` +"import { a //comment1 +//comment2 +//comment3 +as b} from \\"\\"; + +import { + a as //comment1 + //comment2 + //comment3 + b +} from \\"\\"; + +import { + a as //comment2 //comment1 + //comment3 + b +} from \\"\\"; + +import { + a as //comment3 //comment2 //comment1 + b +} from \\"\\"; +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +import { + //comment1 + //comment2 + //comment3 + a as b +} from \\"\\"; + +import { + //comment1 + //comment2 + //comment3 + a as b +} from \\"\\"; + +import { + //comment2 //comment1 + //comment3 + a as b +} from \\"\\"; + +import { + //comment3 //comment2 //comment1 + a as b +} from \\"\\"; +" +`; + exports[`long-line.js 1`] = ` "import someCoolUtilWithARatherLongName from '../../../../utils/someCoolUtilWithARatherLongName'; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -172,6 +328,22 @@ import someCoolUtilWithARatherLongName " `; +exports[`long-line.js 3`] = ` +"import someCoolUtilWithARatherLongName from '../../../../utils/someCoolUtilWithARatherLongName'; +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +import someCoolUtilWithARatherLongName + from \\"../../../../utils/someCoolUtilWithARatherLongName\\"; +" +`; + +exports[`long-line.js 4`] = ` +"import someCoolUtilWithARatherLongName from '../../../../utils/someCoolUtilWithARatherLongName'; +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +import someCoolUtilWithARatherLongName + from \\"../../../../utils/someCoolUtilWithARatherLongName\\"; +" +`; + exports[`multiple_standalones.js 1`] = ` "import a, * as b from 'a'; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -185,3 +357,17 @@ exports[`multiple_standalones.js 2`] = ` import a, * as b from \\"a\\"; " `; + +exports[`multiple_standalones.js 3`] = ` +"import a, * as b from 'a'; +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +import a, * as b from \\"a\\"; +" +`; + +exports[`multiple_standalones.js 4`] = ` +"import a, * as b from 'a'; +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +import a, * as b from \\"a\\"; +" +`; diff --git a/tests/import/jsfmt.spec.js b/tests/import/jsfmt.spec.js index 7e2f65bc9..3dc54d59d 100644 --- a/tests/import/jsfmt.spec.js +++ b/tests/import/jsfmt.spec.js @@ -1,2 +1,5 @@ run_spec(__dirname); run_spec(__dirname, {bracketSpacing: false}); + +run_spec(__dirname, {parser: 'typescript'}); +run_spec(__dirname, {parser: 'typescript', bracketSpacing: false}); diff --git a/tests/it/__snapshots__/jsfmt.spec.js.snap b/tests/it/__snapshots__/jsfmt.spec.js.snap index 512642246..8baf615e3 100644 --- a/tests/it/__snapshots__/jsfmt.spec.js.snap +++ b/tests/it/__snapshots__/jsfmt.spec.js.snap @@ -128,3 +128,132 @@ it.only.only( ); " `; + +exports[`it.js 2`] = ` +"// Shouldn't break + +it(\\"does something really long and complicated so I have to write a very long name for the test\\", () => { + console.log(\\"hello!\\"); +}); + +it(\\"does something really long and complicated so I have to write a very long name for the test\\", function() { + console.log(\\"hello!\\"); +}); + +it(\`does something really long and complicated so I have to write a very long name for the test\`, function() { + console.log(\\"hello!\\"); +}); + +it(\`{foo + bar} does something really long and complicated so I have to write a very long name for the test\`, function() { + console.log(\\"hello!\\"); +}); + +it(\`handles + some + newlines + does something really long and complicated so I have to write a very long name for the test\`, () => { + console.log(\\"hello!\\"); +}) + +test(\\"does something really long and complicated so I have to write a very long name for the test\\", (done) => { + console.log(\\"hello!\\"); +}); + +test(\`does something really long and complicated so I have to write a very long name for the test\`, (done) => { + console.log(\\"hello!\\"); +}); + +// Should break + +it.only(\\"does something really long and complicated so I have to write a very long name for the test\\", () => { + console.log(\\"hello!\\"); +}); + +it.only(\`does something really long and complicated so I have to write a very long name for the test\`, () => { + console.log(\\"hello!\\"); +}); + +it.only(\\"does something really long and complicated so I have to write a very long name for the test\\", 10, () => { + console.log(\\"hello!\\"); +}); + +it.only.only(\\"does something really long and complicated so I have to write a very long name for the test\\", () => { + console.log(\\"hello!\\"); +}); + +it.only.only(\\"does something really long and complicated so I have to write a very long name for the test\\", (a, b, c) => { + console.log(\\"hello!\\"); +}); +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +// Shouldn't break + +it(\\"does something really long and complicated so I have to write a very long name for the test\\", () => { + console.log(\\"hello!\\"); +}); + +it(\\"does something really long and complicated so I have to write a very long name for the test\\", function() { + console.log(\\"hello!\\"); +}); + +it(\`does something really long and complicated so I have to write a very long name for the test\`, function() { + console.log(\\"hello!\\"); +}); + +it(\`{foo + bar} does something really long and complicated so I have to write a very long name for the test\`, function() { + console.log(\\"hello!\\"); +}); + +it(\`handles + some + newlines + does something really long and complicated so I have to write a very long name for the test\`, () => { + console.log(\\"hello!\\"); +}); + +test(\\"does something really long and complicated so I have to write a very long name for the test\\", done => { + console.log(\\"hello!\\"); +}); + +test(\`does something really long and complicated so I have to write a very long name for the test\`, done => { + console.log(\\"hello!\\"); +}); + +// Should break + +it.only( + \\"does something really long and complicated so I have to write a very long name for the test\\", + () => { + console.log(\\"hello!\\"); + } +); + +it.only( + \`does something really long and complicated so I have to write a very long name for the test\`, + () => { + console.log(\\"hello!\\"); + } +); + +it.only( + \\"does something really long and complicated so I have to write a very long name for the test\\", + 10, + () => { + console.log(\\"hello!\\"); + } +); + +it.only.only( + \\"does something really long and complicated so I have to write a very long name for the test\\", + () => { + console.log(\\"hello!\\"); + } +); + +it.only.only( + \\"does something really long and complicated so I have to write a very long name for the test\\", + (a, b, c) => { + console.log(\\"hello!\\"); + } +); +" +`; diff --git a/tests/it/jsfmt.spec.js b/tests/it/jsfmt.spec.js index 989047bcc..1161d7bfb 100644 --- a/tests/it/jsfmt.spec.js +++ b/tests/it/jsfmt.spec.js @@ -1 +1,2 @@ run_spec(__dirname); +run_spec(__dirname, {parser: 'typescript'}); \ No newline at end of file diff --git a/tests/jsx-multiline-assign/__snapshots__/jsfmt.spec.js.snap b/tests/jsx-multiline-assign/__snapshots__/jsfmt.spec.js.snap index 081bf0d14..f3c81c431 100644 --- a/tests/jsx-multiline-assign/__snapshots__/jsfmt.spec.js.snap +++ b/tests/jsx-multiline-assign/__snapshots__/jsfmt.spec.js.snap @@ -52,3 +52,56 @@ const comp4 = ( const comp5 =
+ Welcome to the Universal React Starter-kyt. + This starter kyt should serve as the base for an advanced, + server-rendered React app. +
+ +newlines_text = ++ Welcome to the Universal React Starter-kyt. + This starter kyt should serve as the base for an advanced, + server-rendered React app. +
+); + +newlines_text = ( +foobar bar bar
foobar bar bar