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 =
Keep it on one line.
; " `; + +exports[`test.js 2`] = ` +"const comp1 = ( +
+ Keep the wrapping parens. +
+); + +const comp2 =
+ Create wrapping parens. +
; + +comp2A =
+ Create wrapping parens. +
; + +const comp3 =
Bump to next line without parens
; + +const comp4 =
Create wrapping parens and indent all the things.
; + +const comp5 =
Keep it on one line.
; +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +const comp1 = ( +
+ Keep the wrapping parens. +
+); + +const comp2 = ( +
+ Create wrapping parens. +
+); + +comp2A = ( +
+ Create wrapping parens. +
+); + +const comp3 = ( +
Bump to next line without parens
+); + +const comp4 = ( +
+ Create wrapping parens and indent all the things. +
+); + +const comp5 =
Keep it on one line.
; +" +`; diff --git a/tests/jsx-multiline-assign/jsfmt.spec.js b/tests/jsx-multiline-assign/jsfmt.spec.js index 989047bcc..1161d7bfb 100644 --- a/tests/jsx-multiline-assign/jsfmt.spec.js +++ b/tests/jsx-multiline-assign/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-newlines/__snapshots__/jsfmt.spec.js.snap b/tests/jsx-newlines/__snapshots__/jsfmt.spec.js.snap index 2638cada8..74e727aa2 100644 --- a/tests/jsx-newlines/__snapshots__/jsfmt.spec.js.snap +++ b/tests/jsx-newlines/__snapshots__/jsfmt.spec.js.snap @@ -187,3 +187,191 @@ regression_extra_newline_2 = ( ); " `; + +exports[`test.js 2`] = ` +"keep =

+ Welcome to the Universal React Starter-kyt. + This starter kyt should serve as the base for an advanced, + server-rendered React app. +

+ +newlines_text = +
+ hi + there + how + + are you + + + are you fine today? +
+ +newlines_text_spaced = +
+ + space above + + space below + +
+ +newlines_elems_spaced = +
+ + space above + + space below + +
+ +newlines_mixed = +
+ hi + there + + how + + are you + + + are you fine today? +
+ +newlines_elems = +
+
+ + +
+ + +
+ + + hi + + +
+ + + + + + + + +
+ +regression_extra_newline = ( +
+ + New Messages +
+); + + +regression_extra_newline_2 = ( +
+ ( + + ) +
+); +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +keep = ( +

+ Welcome to the Universal React Starter-kyt. + This starter kyt should serve as the base for an advanced, + server-rendered React app. +

+); + +newlines_text = ( +
+ hi + there + how + + are you + + are you fine today? +
+); + +newlines_text_spaced = ( +
+ + space above + + space below + +
+); + +newlines_elems_spaced = ( +
+ + space above + + space below + +
+); + +newlines_mixed = ( +
+ hi + there + + how + + are you + + are you fine today? +
+); + +newlines_elems = ( +
+
+ +
+ +
+ + hi + +
+ + + + + +
+); + +regression_extra_newline = ( +
+ + New Messages +
+); + +regression_extra_newline_2 = ( +
+ ( + + ) +
+); +" +`; diff --git a/tests/jsx-newlines/jsfmt.spec.js b/tests/jsx-newlines/jsfmt.spec.js index 989047bcc..1161d7bfb 100644 --- a/tests/jsx-newlines/jsfmt.spec.js +++ b/tests/jsx-newlines/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-significant-space/__snapshots__/jsfmt.spec.js.snap b/tests/jsx-significant-space/__snapshots__/jsfmt.spec.js.snap index 36c0f42c9..301b52b6d 100644 --- a/tests/jsx-significant-space/__snapshots__/jsfmt.spec.js.snap +++ b/tests/jsx-significant-space/__snapshots__/jsfmt.spec.js.snap @@ -198,3 +198,202 @@ not_broken_begin = ( ); " `; + +exports[`test.js 2`] = ` +"after = + + foo bar + + +before = + + bar foo + + +before_break1 = + + foo + + +before_break2 = + + foo + + +after_break = + + foo + + +within = + + foo bar + + +break_components = +
+ + +

foobar bar bar

yep

+
+

nope

+
+ +var x =
+ hello hi sdkflsdfjk +
; + +nest_plz = +
+
+
+
+
+ +regression_not_transformed_1 = + ; + +regression_not_transformed_2 = + ; + +similar_1 = + ; + +similar_2 = + ; + +similar_3 = + ; + +not_broken_end = +
+ long text long text long text long text long text long text long text long text url long text long text +
+ +not_broken_begin = +
+
long text long text long text long text long text long text long text long texturl long text long text +
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +after = ( + + foo bar + +); + +before = ( + + bar foo + +); + +before_break1 = ( + + + {\\" \\"} + foo + +); + +before_break2 = ( + + + {\\" \\"} + foo + +); + +after_break = ( + + foo + {\\" \\"} + + +); + +within = ( + + foo bar + +); + +break_components = ( +
+ + +

foobar bar bar

yep

+
+

nope

+
+); + +var x = ( +
+ hello hi sdkflsdfjk +
+); + +nest_plz = ( +
+
+
+
+
+); + +regression_not_transformed_1 = ( + + {\\" \\"} + +); + +regression_not_transformed_2 = ( + + {\\" \\"} + +); + +similar_1 = ( + + {\\" \\"} + + +); + +similar_2 = ( + + + {\\" \\"} + +); + +similar_3 = ( + + + +); + +not_broken_end = ( +
+ long text long text long text long text long text long text long text long text + {\\" \\"} + url + {\\" \\"} + long text long text +
+); + +not_broken_begin = ( +
+
+ {\\" \\"} + long text long text long text long text long text long text long text long text + url + {\\" \\"} + long text long text +
+); +" +`; diff --git a/tests/jsx-significant-space/jsfmt.spec.js b/tests/jsx-significant-space/jsfmt.spec.js index 989047bcc..1161d7bfb 100644 --- a/tests/jsx-significant-space/jsfmt.spec.js +++ b/tests/jsx-significant-space/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-split-attrs/__snapshots__/jsfmt.spec.js.snap b/tests/jsx-split-attrs/__snapshots__/jsfmt.spec.js.snap index efb23b71d..4b1f99702 100644 --- a/tests/jsx-split-attrs/__snapshots__/jsfmt.spec.js.snap +++ b/tests/jsx-split-attrs/__snapshots__/jsfmt.spec.js.snap @@ -212,3 +212,216 @@ long_obj = ( ); " `; + +exports[`test.js 2`] = ` +"long_closed = + + +long_open = + + hello + + +long_open_long_children = + + + Hello world + +
hey hiya how are ya
+
+
+
+
+ d + + + +short_closed = + + +short_open = + + hello + + +make_self_closing = +
+ + + +
+ +leave_opening = + + +long_string = +
hello world
+ +long_string_with_extra_param = +
hello world
+ +long_obj = +
hello world
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +long_closed = ( + +); + +long_open = ( + + hello + +); + +long_open_long_children = ( + + + Hello world + +
+
hey hiya how are ya
+
+
+
+
+
+
+
+
+
+
+
+
+
+ + + d + + + + + +); + +short_closed = ; + +short_open = ( + + hello + +); + +make_self_closing = ( +
+ + +
+); + +leave_opening = ( + + {\\" \\"} + +); + +long_string = ( +
+ hello world +
+); + +long_string_with_extra_param = ( +
+ hello world +
+); + +long_obj = ( +
+ hello world +
+); +" +`; diff --git a/tests/jsx-split-attrs/jsfmt.spec.js b/tests/jsx-split-attrs/jsfmt.spec.js index 989047bcc..1161d7bfb 100644 --- a/tests/jsx-split-attrs/jsfmt.spec.js +++ b/tests/jsx-split-attrs/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-stateless-arrow-fn/__snapshots__/jsfmt.spec.js.snap b/tests/jsx-stateless-arrow-fn/__snapshots__/jsfmt.spec.js.snap index 21a7ac786..953856572 100644 --- a/tests/jsx-stateless-arrow-fn/__snapshots__/jsfmt.spec.js.snap +++ b/tests/jsx-stateless-arrow-fn/__snapshots__/jsfmt.spec.js.snap @@ -232,3 +232,236 @@ const renderTernary = props => ( ); " `; + +exports[`test.js 2`] = ` +"const render1 = ({ styles }) => ( +
+ Keep the wrapping parens. Put each key on its own line. +
+); + +const render2 = ({ styles }) =>
+ Create wrapping parens. +
; + +const render3 = ({ styles }) =>
Bump to next line without parens
; + +const render4 = ({ styles }) =>
Create wrapping parens and indent all the things.
; + +const render5 = ({ styles }) =>
Keep it on one line.
; + +const render6 = ({ styles }) => ( +
+
ddd d dd d d dddd dddd hello
+
ddd d dd d d dddd dddd hello
+
+
ddd d dd d d dddd dddd hello
hello
+
+) + +const render7 = () => +
+ Dont break each elem onto its own line. +
+
+ +const render7A = () => ( +
+
+
+) + +const render7B = () => ( +
+ Dont break plz + Dont break plz + Dont break plz +
+) + +const render8 = (props) =>
{props.text}
+const render9 = (props) =>
{props.looooooooooooooooooooooooooooooong_text}
+const render10 = (props) =>
{props.even_looooooooooooooooooooooooooooooooooooooooooonger_contents}
+ +const notJSX = (aaaaaaaaaaaaaaaaa, bbbbbbbbbbb) => this.someLongCallWithParams(aaaaaa, bbbbbbb).anotherLongCallWithParams(cccccccccccc, dddddddddddddddddddddd) + +React.render( + + , document.querySelector('#react-root') +) + + +const renderTernary = (props) => + + {props.showTheThing ? + Hello world + : \\"hello \\" + \\"howdy! \\"} + {props.showTheThing ? + Hello world + : + null + } + {props.showTheThing ? null : + Hello world + } + {props.showTheOtherThing ?
I am here
:
} + {props.showTheOtherThing ?
I am here!!
: null} + +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +const render1 = ({ styles }) => ( +
+ Keep the wrapping parens. Put each key on its own line. +
+); + +const render2 = ({ styles }) => ( +
+ Create wrapping parens. +
+); + +const render3 = ({ styles }) => ( +
Bump to next line without parens
+); + +const render4 = ({ styles }) => ( +
+ Create wrapping parens and indent all the things. +
+); + +const render5 = ({ styles }) =>
Keep it on one line.
; + +const render6 = ({ styles }) => ( +
+
+ ddd d dd d d dddd dddd hello +
+
+ ddd d dd d d dddd dddd hello +
+
+
+ ddd d dd d d dddd dddd hello +
+ {\\" \\"} + hello +
+
+); + +const render7 = () => ( +
+ Dont break each elem onto its own line. +
+
+); + +const render7A = () => ( +
+
+
+); + +const render7B = () => ( +
+ Dont break plz + Dont break plz + Dont break plz +
+); + +const render8 = props =>
{props.text}
; +const render9 = props => ( +
{props.looooooooooooooooooooooooooooooong_text}
+); +const render10 = props => ( +
+ {props.even_looooooooooooooooooooooooooooooooooooooooooonger_contents} +
+); + +const notJSX = (aaaaaaaaaaaaaaaaa, bbbbbbbbbbb) => + this.someLongCallWithParams(aaaaaa, bbbbbbb).anotherLongCallWithParams( + cccccccccccc, + dddddddddddddddddddddd + ); + +React.render( + , + document.querySelector(\\"#react-root\\") +); + +const renderTernary = props => ( + + {props.showTheThing + ? + Hello world + + : \\"hello \\" + \\"howdy! \\"} + {props.showTheThing + ? + Hello world + + : null} + {props.showTheThing + ? null + : + Hello world + } + {props.showTheOtherThing ?
I am here
:
} + {props.showTheOtherThing ?
I am here!!
: null} + +); +" +`; diff --git a/tests/jsx-stateless-arrow-fn/jsfmt.spec.js b/tests/jsx-stateless-arrow-fn/jsfmt.spec.js index 989047bcc..1161d7bfb 100644 --- a/tests/jsx-stateless-arrow-fn/jsfmt.spec.js +++ b/tests/jsx-stateless-arrow-fn/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/__snapshots__/jsfmt.spec.js.snap b/tests/jsx/__snapshots__/jsfmt.spec.js.snap index 9f8448b4c..39a45bb3b 100644 --- a/tests/jsx/__snapshots__/jsfmt.spec.js.snap +++ b/tests/jsx/__snapshots__/jsfmt.spec.js.snap @@ -139,6 +139,145 @@ exports[`expression.js 1`] = ` " `; +exports[`expression.js 2`] = ` +"; + +; + + + {() => ( + + + + )} +; + + + {items.map(item => ( + + + + ))} +; + + + {function() { + return ( + + + + ); + }} +; + +; + + + test + +}/>; +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +; + +; + + + {() => ( + + + + )} +; + + + {items.map(item => ( + + + + ))} +; + + + {function() { + return ( + + + + ); + }} +; + +; + + + test + + } +/>; +" +`; + exports[`hug.js 1`] = ` "
{__DEV__ @@ -199,6 +338,66 @@ exports[`hug.js 1`] = ` " `; +exports[`hug.js 2`] = ` +"
+ {__DEV__ + ? this.renderDevApp() + :
+ {routes.map(route => ( + + ))} +
} +
; + +
+ {__DEV__ &&
+ {routes.map(route => ( + + ))} +
} +
; +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +
+ {__DEV__ + ? this.renderDevApp() + :
+ {routes.map(route => ( + + ))} +
} +
; + +
+ {__DEV__ && +
+ {routes.map(route => ( + + ))} +
} +
; +" +`; + exports[`object-property.js 1`] = ` "const tabs = [ { @@ -230,6 +429,37 @@ const tabs = [ " `; +exports[`object-property.js 2`] = ` +"const tabs = [ + { + title: \\"General Info\\", + content: ( + + ) + } +]; +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +const tabs = [ + { + title: \\"General Info\\", + content: ( + + ) + } +]; +" +`; + exports[`open-break.js 1`] = ` " { @@ -260,6 +490,36 @@ onClick={() => { " `; +exports[`open-break.js 2`] = ` +" { + a +}}>{header}{showSort}; + + { + a +}}>{header}; +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + { + a; + }} +> + {header}{showSort} +; + + { + a; + }} +> + {header} + +; +" +`; + exports[`parens.js 1`] = ` "a = [ , + , +]; +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +a = [ + , + +]; +" +`; + exports[`quotes.js 1`] = ` "
&quot;\\" />;
; @@ -295,3 +580,14 @@ exports[`quotes.js 1`] = `
&quot;\\"} />; " `; + +exports[`quotes.js 2`] = ` +"
&quot;\\" />; +
; +
&quot;'} />; +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +
&quot;\\" />; +
&quot;\\" />; +
&quot;\\"} />; +" +`; diff --git a/tests/jsx/jsfmt.spec.js b/tests/jsx/jsfmt.spec.js index 989047bcc..1161d7bfb 100644 --- a/tests/jsx/jsfmt.spec.js +++ b/tests/jsx/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_last_line/__snapshots__/jsfmt.spec.js.snap b/tests/jsx_last_line/__snapshots__/jsfmt.spec.js.snap index 706d39b71..d56dd3e59 100644 --- a/tests/jsx_last_line/__snapshots__/jsfmt.spec.js.snap +++ b/tests/jsx_last_line/__snapshots__/jsfmt.spec.js.snap @@ -48,3 +48,52 @@ exports[`last_line.js 2`] = ` ; " `; + +exports[`last_line.js 3`] = ` +" +
and the children go here
+
and here too
+
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +
and the children go here
+
and here too
+
; +" +`; + +exports[`last_line.js 4`] = ` +" +
and the children go here
+
and here too
+
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +
and the children go here
+
and here too
+
; +" +`; diff --git a/tests/jsx_last_line/jsfmt.spec.js b/tests/jsx_last_line/jsfmt.spec.js index 0cac44995..eeb2ed9fe 100644 --- a/tests/jsx_last_line/jsfmt.spec.js +++ b/tests/jsx_last_line/jsfmt.spec.js @@ -1,2 +1,5 @@ run_spec(__dirname, {jsxBracketSameLine: true}); run_spec(__dirname, {jsxBracketSameLine: false}); + +run_spec(__dirname, {parser: 'typescript', jsxBracketSameLine: true}); +run_spec(__dirname, {parser: 'typescript', jsxBracketSameLine: false}); diff --git a/tests/label/__snapshots__/jsfmt.spec.js.snap b/tests/label/__snapshots__/jsfmt.spec.js.snap index 2be86bcb4..179cda189 100644 --- a/tests/label/__snapshots__/jsfmt.spec.js.snap +++ b/tests/label/__snapshots__/jsfmt.spec.js.snap @@ -8,3 +8,12 @@ a:; b; " `; + +exports[`empty_label.js 2`] = ` +"a:; +b +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +a:; +b; +" +`; diff --git a/tests/label/jsfmt.spec.js b/tests/label/jsfmt.spec.js index 989047bcc..1161d7bfb 100644 --- a/tests/label/jsfmt.spec.js +++ b/tests/label/jsfmt.spec.js @@ -1 +1,2 @@ run_spec(__dirname); +run_spec(__dirname, {parser: 'typescript'}); \ No newline at end of file diff --git a/tests/line/__snapshots__/jsfmt.spec.js.snap b/tests/line/__snapshots__/jsfmt.spec.js.snap index 2869d3af8..6d76a8fbf 100644 --- a/tests/line/__snapshots__/jsfmt.spec.js.snap +++ b/tests/line/__snapshots__/jsfmt.spec.js.snap @@ -14,3 +14,18 @@ let outChannel; let _commands; " `; + +exports[`windows.js 2`] = ` +"const vscode = require(\\"vscode\\"); +const {getDir, getActiveFile, uint8arrayToString} = require(\\"./utils\\"); + +let outChannel; +let _commands; +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +const vscode = require(\\"vscode\\"); +const { getDir, getActiveFile, uint8arrayToString } = require(\\"./utils\\"); + +let outChannel; +let _commands; +" +`; diff --git a/tests/line/jsfmt.spec.js b/tests/line/jsfmt.spec.js index 989047bcc..1161d7bfb 100644 --- a/tests/line/jsfmt.spec.js +++ b/tests/line/jsfmt.spec.js @@ -1 +1,2 @@ run_spec(__dirname); +run_spec(__dirname, {parser: 'typescript'}); \ No newline at end of file diff --git a/tests/member/__snapshots__/jsfmt.spec.js.snap b/tests/member/__snapshots__/jsfmt.spec.js.snap index bdf546b4c..4263d57b0 100644 --- a/tests/member/__snapshots__/jsfmt.spec.js.snap +++ b/tests/member/__snapshots__/jsfmt.spec.js.snap @@ -9,3 +9,13 @@ const veryVeryVeryVeryVeryVeryVeryLong = doc.expandedStates[ const small = doc.expandedStates[doc.expandedStates.length - 1]; " `; + +exports[`expand.js 2`] = ` +"const veryVeryVeryVeryVeryVeryVeryLong = doc.expandedStates[doc.expandedStates.length - 1]; +const small = doc.expandedStates[doc.expandedStates.length - 1];~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +const veryVeryVeryVeryVeryVeryVeryLong = doc.expandedStates[ + doc.expandedStates.length - 1 +]; +const small = doc.expandedStates[doc.expandedStates.length - 1]; +" +`; diff --git a/tests/member/jsfmt.spec.js b/tests/member/jsfmt.spec.js index 989047bcc..1161d7bfb 100644 --- a/tests/member/jsfmt.spec.js +++ b/tests/member/jsfmt.spec.js @@ -1 +1,2 @@ run_spec(__dirname); +run_spec(__dirname, {parser: 'typescript'}); \ No newline at end of file diff --git a/tests/new_expression/__snapshots__/jsfmt.spec.js.snap b/tests/new_expression/__snapshots__/jsfmt.spec.js.snap index 8d096e8b6..1445f2e48 100644 --- a/tests/new_expression/__snapshots__/jsfmt.spec.js.snap +++ b/tests/new_expression/__snapshots__/jsfmt.spec.js.snap @@ -8,3 +8,12 @@ new (memoize.Cache || MapCache)(); new (typeof this == \\"function\\" ? this : Dict())(); " `; + +exports[`new_expression.js 2`] = ` +"new (memoize.Cache || MapCache) +new (typeof this == \\"function\\" ? this : Dict()) +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +new (memoize.Cache || MapCache)(); +new (typeof this == \\"function\\" ? this : Dict())(); +" +`; diff --git a/tests/new_expression/jsfmt.spec.js b/tests/new_expression/jsfmt.spec.js index 989047bcc..1161d7bfb 100644 --- a/tests/new_expression/jsfmt.spec.js +++ b/tests/new_expression/jsfmt.spec.js @@ -1 +1,2 @@ run_spec(__dirname); +run_spec(__dirname, {parser: 'typescript'}); \ No newline at end of file diff --git a/tests/object-prop-break-in/__snapshots__/jsfmt.spec.js.snap b/tests/object-prop-break-in/__snapshots__/jsfmt.spec.js.snap index 051df4d55..8227b17ad 100644 --- a/tests/object-prop-break-in/__snapshots__/jsfmt.spec.js.snap +++ b/tests/object-prop-break-in/__snapshots__/jsfmt.spec.js.snap @@ -17,6 +17,23 @@ function foo() { " `; +exports[`comment.js 2`] = ` +"function foo() { + return { + // this comment causes the problem + bar: baz() + 1 + }; +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +function foo() { + return { + // this comment causes the problem + bar: baz() + 1 + }; +} +" +`; + exports[`test.js 1`] = ` "const a = classnames({ \\"some-prop\\": this.state.longLongLongLongLongLongLongLongLongTooLongProp @@ -77,3 +94,64 @@ const g = classnames({ }); " `; + +exports[`test.js 2`] = ` +"const a = classnames({ + \\"some-prop\\": this.state.longLongLongLongLongLongLongLongLongTooLongProp +}); + +const b = classnames({ + \\"some-prop\\": this.state.longLongLongLongLongLongLongLongLongTooLongProp === true +}); + +const c = classnames({ + \\"some-prop\\": [ \\"foo\\", \\"bar\\", \\"foo\\", \\"bar\\", \\"foo\\", \\"bar\\", \\"foo\\", \\"bar\\", \\"foo\\" ] +}); + +const d = classnames({ + \\"some-prop\\": () => {} +}); + +const e = classnames({ + \\"some-prop\\": function bar() {} +}); + +const f = classnames({ + \\"some-prop\\": { foo: \\"bar\\", bar: \\"foo\\", foo: \\"bar\\", bar: \\"foo\\", foo: \\"bar\\" } +}); + +const g = classnames({ + \\"some-prop\\": longLongLongLongLongLongLongLongLongLongLongLongLongTooLongVar || 1337 +}); +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +const a = classnames({ + \\"some-prop\\": this.state.longLongLongLongLongLongLongLongLongTooLongProp +}); + +const b = classnames({ + \\"some-prop\\": this.state.longLongLongLongLongLongLongLongLongTooLongProp === + true +}); + +const c = classnames({ + \\"some-prop\\": [\\"foo\\", \\"bar\\", \\"foo\\", \\"bar\\", \\"foo\\", \\"bar\\", \\"foo\\", \\"bar\\", \\"foo\\"] +}); + +const d = classnames({ + \\"some-prop\\": () => {} +}); + +const e = classnames({ + \\"some-prop\\": function bar() {} +}); + +const f = classnames({ + \\"some-prop\\": { foo: \\"bar\\", bar: \\"foo\\", foo: \\"bar\\", bar: \\"foo\\", foo: \\"bar\\" } +}); + +const g = classnames({ + \\"some-prop\\": longLongLongLongLongLongLongLongLongLongLongLongLongTooLongVar || + 1337 +}); +" +`; diff --git a/tests/object-prop-break-in/jsfmt.spec.js b/tests/object-prop-break-in/jsfmt.spec.js index 989047bcc..1161d7bfb 100644 --- a/tests/object-prop-break-in/jsfmt.spec.js +++ b/tests/object-prop-break-in/jsfmt.spec.js @@ -1 +1,2 @@ run_spec(__dirname); +run_spec(__dirname, {parser: 'typescript'}); \ No newline at end of file diff --git a/tests/object_colon_bug/__snapshots__/jsfmt.spec.js.snap b/tests/object_colon_bug/__snapshots__/jsfmt.spec.js.snap index aefdc358d..06ab37f72 100644 --- a/tests/object_colon_bug/__snapshots__/jsfmt.spec.js.snap +++ b/tests/object_colon_bug/__snapshots__/jsfmt.spec.js.snap @@ -14,3 +14,18 @@ const foo = { }; " `; + +exports[`bug.js 2`] = ` +"const foo = { + bar: props.bar ? props.bar : noop, + baz: props.baz +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +const foo = { + bar: props.bar + ? props.bar + : noop, + baz: props.baz +}; +" +`; diff --git a/tests/object_colon_bug/jsfmt.spec.js b/tests/object_colon_bug/jsfmt.spec.js index c92e1fa6a..dd7b4638b 100644 --- a/tests/object_colon_bug/jsfmt.spec.js +++ b/tests/object_colon_bug/jsfmt.spec.js @@ -1 +1,2 @@ run_spec(__dirname, {printWidth: 35}); +run_spec(__dirname, {parser: 'typescript', printWidth: 35}); \ No newline at end of file diff --git a/tests/preserve_line/__snapshots__/jsfmt.spec.js.snap b/tests/preserve_line/__snapshots__/jsfmt.spec.js.snap index acb62f28f..68aa4eb2a 100644 --- a/tests/preserve_line/__snapshots__/jsfmt.spec.js.snap +++ b/tests/preserve_line/__snapshots__/jsfmt.spec.js.snap @@ -60,3 +60,64 @@ function a() { } " `; + +exports[`comments.js 2`] = ` +"function a() { + const a = 5; // comment + + return a; +} + +function a() { + const a = 5; /* comment */ + + return a; +} + +function a() { + const a = 5; /* comment */ /* comment */ + + return a; +} + +function a() { + const a = 5; /* comment */ /* comment */ // comment + return a; +} + +function a() { + const a = 5; /* comment */ /* comment */ // comment + + return a; +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +function a() { + const a = 5; // comment + + return a; +} + +function a() { + const a = 5; /* comment */ + + return a; +} + +function a() { + const a = 5; /* comment */ /* comment */ + + return a; +} + +function a() { + const a = 5; /* comment */ /* comment */ // comment + return a; +} + +function a() { + const a = 5; /* comment */ /* comment */ // comment + + return a; +} +" +`; diff --git a/tests/preserve_line/jsfmt.spec.js b/tests/preserve_line/jsfmt.spec.js index 989047bcc..1161d7bfb 100644 --- a/tests/preserve_line/jsfmt.spec.js +++ b/tests/preserve_line/jsfmt.spec.js @@ -1 +1,2 @@ run_spec(__dirname); +run_spec(__dirname, {parser: 'typescript'}); \ No newline at end of file diff --git a/tests/require/__snapshots__/jsfmt.spec.js.snap b/tests/require/__snapshots__/jsfmt.spec.js.snap index 9c2bd9587..2cc0c6b02 100644 --- a/tests/require/__snapshots__/jsfmt.spec.js.snap +++ b/tests/require/__snapshots__/jsfmt.spec.js.snap @@ -35,3 +35,39 @@ const { const MyReallyExtrememlyLongModuleName = require(\\"MyReallyExtrememlyLongModuleName\\"); " `; + +exports[`require.js 2`] = ` +"const { one, two, thee, four, five, six, seven, eight, nine, ten } = require('./my-utils'); +const { one, two, thee, four, five, six, seven, eight, nine, ten, eleven } = require('./my-utils'); + +const MyReallyExtrememlyLongModuleName = require('MyReallyExtrememlyLongModuleName'); +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +const { + one, + two, + thee, + four, + five, + six, + seven, + eight, + nine, + ten +} = require(\\"./my-utils\\"); +const { + one, + two, + thee, + four, + five, + six, + seven, + eight, + nine, + ten, + eleven +} = require(\\"./my-utils\\"); + +const MyReallyExtrememlyLongModuleName = require(\\"MyReallyExtrememlyLongModuleName\\"); +" +`; diff --git a/tests/require/jsfmt.spec.js b/tests/require/jsfmt.spec.js index 989047bcc..1161d7bfb 100644 --- a/tests/require/jsfmt.spec.js +++ b/tests/require/jsfmt.spec.js @@ -1 +1,2 @@ run_spec(__dirname); +run_spec(__dirname, {parser: 'typescript'}); \ No newline at end of file diff --git a/tests/shebang/__snapshots__/jsfmt.spec.js.snap b/tests/shebang/__snapshots__/jsfmt.spec.js.snap index e6c317e7f..ee799cb7e 100644 --- a/tests/shebang/__snapshots__/jsfmt.spec.js.snap +++ b/tests/shebang/__snapshots__/jsfmt.spec.js.snap @@ -9,6 +9,15 @@ function a() {} " `; +exports[`shebang.js 2`] = ` +"#!/usr/bin/env node +function a() {} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +#!/usr/bin/env node +function a() {} +" +`; + exports[`shebang-newline.js 1`] = ` "#!/usr/bin/env node @@ -19,3 +28,14 @@ function a() {} function a() {} " `; + +exports[`shebang-newline.js 2`] = ` +"#!/usr/bin/env node + +function a() {} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +#!/usr/bin/env node + +function a() {} +" +`; diff --git a/tests/shebang/jsfmt.spec.js b/tests/shebang/jsfmt.spec.js index 989047bcc..1161d7bfb 100644 --- a/tests/shebang/jsfmt.spec.js +++ b/tests/shebang/jsfmt.spec.js @@ -1 +1,2 @@ run_spec(__dirname); +run_spec(__dirname, {parser: 'typescript'}); \ No newline at end of file diff --git a/tests/switch/__snapshots__/jsfmt.spec.js.snap b/tests/switch/__snapshots__/jsfmt.spec.js.snap index 9768792e8..57d35be47 100644 --- a/tests/switch/__snapshots__/jsfmt.spec.js.snap +++ b/tests/switch/__snapshots__/jsfmt.spec.js.snap @@ -11,3 +11,15 @@ switch (1) { } " `; + +exports[`empty_switch.js 2`] = ` +"switch (1) { default:; } +switch (1) {} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +switch (1) { + default: +} +switch (1) { +} +" +`; diff --git a/tests/switch/jsfmt.spec.js b/tests/switch/jsfmt.spec.js index 989047bcc..1161d7bfb 100644 --- a/tests/switch/jsfmt.spec.js +++ b/tests/switch/jsfmt.spec.js @@ -1 +1,2 @@ run_spec(__dirname); +run_spec(__dirname, {parser: 'typescript'}); \ No newline at end of file diff --git a/tests/template/__snapshots__/jsfmt.spec.js.snap b/tests/template/__snapshots__/jsfmt.spec.js.snap index 5a4933538..39ac372fb 100644 --- a/tests/template/__snapshots__/jsfmt.spec.js.snap +++ b/tests/template/__snapshots__/jsfmt.spec.js.snap @@ -33,6 +33,39 @@ var x = { " `; +exports[`faulty-locations.js 2`] = ` +"var o = { + [\`key\`]: () => { + // Comment + } +}; + +var x = { + y: () => Relay.QL\` + query { + \${foo}, + field, + } + \` +}; +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +var o = { + [\`key\`]: () => { + // Comment + } +}; + +var x = { + y: () => Relay.QL\` + query { + \${foo}, + field, + } + \` +}; +" +`; + exports[`parenthesis.js 1`] = ` "// \\"ArrowFunctionExpression\\" (() => {})\`\`; @@ -145,3 +178,116 @@ function* f() { } " `; + +exports[`parenthesis.js 2`] = ` +"// \\"ArrowFunctionExpression\\" +(() => {})\`\`; + +// \\"AssignmentExpression\\" +(b = c)\`\`; + +// \\"AwaitExpression\\" +async function f() { + (await b)\`\`; +} + +// \\"BinaryExpression\\" +(b + c)\`\`; + +// \\"CallExpression\\" +b()\`\`; + +// \\"ClassExpression\\" +(class {})\`\`; + +// \\"ConditionalExpression\\" +(b ? c : d)\`\`; + +// \\"FunctionExpression\\" +(function() {})\`\`; + +// \\"LogicalExpression\\" +(b || c)\`\`; + +// \\"MemberExpression\\" +b.c\`\`; + +// \\"NewExpression\\" +(new B())\`\`; + +// \\"ObjectExpression\\" +({})\`\`; + +// \\"SequenceExpression\\" +(b, c)\`\`; + +// \\"TaggedTemplateExpression\\" +(\`\`)\`\`; + +// \\"UnaryExpression\\" +(void b)\`\`; + +// \\"UpdateExpression\\" +(++b)\`\`; + +// \\"YieldExpression\\" +function* f() { + (yield 1)\`\`; +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +// \\"ArrowFunctionExpression\\" +(() => {})\`\`; + +// \\"AssignmentExpression\\" +(b = c)\`\`; + +// \\"AwaitExpression\\" +async function f() { + (await b)\`\`; +} + +// \\"BinaryExpression\\" +(b + c)\`\`; + +// \\"CallExpression\\" +b()\`\`; + +// \\"ClassExpression\\" +(class {}\`\`); + +// \\"ConditionalExpression\\" +(b ? c : d)\`\`; + +// \\"FunctionExpression\\" +(function() {})\`\`; + +// \\"LogicalExpression\\" +(b || c)\`\`; + +// \\"MemberExpression\\" +b.c\`\`; + +// \\"NewExpression\\" +new B()\`\`; + +// \\"ObjectExpression\\" +({}\`\`); + +// \\"SequenceExpression\\" +(b, c)\`\`; + +// \\"TaggedTemplateExpression\\" +\`\`\`\`; + +// \\"UnaryExpression\\" +(void b)\`\`; + +// \\"UpdateExpression\\" +(++b)\`\`; + +// \\"YieldExpression\\" +function* f() { + (yield 1)\`\`; +} +" +`; diff --git a/tests/template/jsfmt.spec.js b/tests/template/jsfmt.spec.js index 989047bcc..1161d7bfb 100644 --- a/tests/template/jsfmt.spec.js +++ b/tests/template/jsfmt.spec.js @@ -1 +1,2 @@ run_spec(__dirname); +run_spec(__dirname, {parser: 'typescript'}); \ No newline at end of file diff --git a/tests/ternaries/__snapshots__/jsfmt.spec.js.snap b/tests/ternaries/__snapshots__/jsfmt.spec.js.snap index 2f2e57dde..d4cdad92b 100644 --- a/tests/ternaries/__snapshots__/jsfmt.spec.js.snap +++ b/tests/ternaries/__snapshots__/jsfmt.spec.js.snap @@ -103,3 +103,107 @@ const obj5 = conditionIsTruthy }; " `; + +exports[`test.js 3`] = ` +"const obj0 = conditionIsTruthy ? shortThing : otherShortThing + +const obj1 = conditionIsTruthy ? { some: 'long', object: 'with', lots: 'of', stuff } : shortThing + +const obj2 = conditionIsTruthy ? shortThing : { some: 'long', object: 'with', lots: 'of', stuff } + +const obj3 = conditionIsTruthy ? { some: 'eeeeeeeeeeeeven looooooooooooooooooooooooooooooonger', object: 'with', lots: 'of', stuff } : shortThing + +const obj4 = conditionIsTruthy ? shortThing : { some: 'eeeeeeeeeeeeven looooooooooooooooooooooooooooooonger', object: 'with', lots: 'of', stuff } + +const obj5 = conditionIsTruthy ? { some: 'long', object: 'with', lots: 'of', stuff } : { some: 'eeeeeeeeeeeeven looooooooooooooooooooooooooooooonger', object: 'with', lots: 'of', stuff } +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +const obj0 = conditionIsTruthy ? shortThing : otherShortThing; + +const obj1 = conditionIsTruthy + ? { some: \\"long\\", object: \\"with\\", lots: \\"of\\", stuff } + : shortThing; + +const obj2 = conditionIsTruthy + ? shortThing + : { some: \\"long\\", object: \\"with\\", lots: \\"of\\", stuff }; + +const obj3 = conditionIsTruthy + ? { + some: \\"eeeeeeeeeeeeven looooooooooooooooooooooooooooooonger\\", + object: \\"with\\", + lots: \\"of\\", + stuff + } + : shortThing; + +const obj4 = conditionIsTruthy + ? shortThing + : { + some: \\"eeeeeeeeeeeeven looooooooooooooooooooooooooooooonger\\", + object: \\"with\\", + lots: \\"of\\", + stuff + }; + +const obj5 = conditionIsTruthy + ? { some: \\"long\\", object: \\"with\\", lots: \\"of\\", stuff } + : { + some: \\"eeeeeeeeeeeeven looooooooooooooooooooooooooooooonger\\", + object: \\"with\\", + lots: \\"of\\", + stuff + }; +" +`; + +exports[`test.js 4`] = ` +"const obj0 = conditionIsTruthy ? shortThing : otherShortThing + +const obj1 = conditionIsTruthy ? { some: 'long', object: 'with', lots: 'of', stuff } : shortThing + +const obj2 = conditionIsTruthy ? shortThing : { some: 'long', object: 'with', lots: 'of', stuff } + +const obj3 = conditionIsTruthy ? { some: 'eeeeeeeeeeeeven looooooooooooooooooooooooooooooonger', object: 'with', lots: 'of', stuff } : shortThing + +const obj4 = conditionIsTruthy ? shortThing : { some: 'eeeeeeeeeeeeven looooooooooooooooooooooooooooooonger', object: 'with', lots: 'of', stuff } + +const obj5 = conditionIsTruthy ? { some: 'long', object: 'with', lots: 'of', stuff } : { some: 'eeeeeeeeeeeeven looooooooooooooooooooooooooooooonger', object: 'with', lots: 'of', stuff } +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +const obj0 = conditionIsTruthy ? shortThing : otherShortThing; + +const obj1 = conditionIsTruthy + ? { some: \\"long\\", object: \\"with\\", lots: \\"of\\", stuff } + : shortThing; + +const obj2 = conditionIsTruthy + ? shortThing + : { some: \\"long\\", object: \\"with\\", lots: \\"of\\", stuff }; + +const obj3 = conditionIsTruthy + ? { + some: \\"eeeeeeeeeeeeven looooooooooooooooooooooooooooooonger\\", + object: \\"with\\", + lots: \\"of\\", + stuff + } + : shortThing; + +const obj4 = conditionIsTruthy + ? shortThing + : { + some: \\"eeeeeeeeeeeeven looooooooooooooooooooooooooooooonger\\", + object: \\"with\\", + lots: \\"of\\", + stuff + }; + +const obj5 = conditionIsTruthy + ? { some: \\"long\\", object: \\"with\\", lots: \\"of\\", stuff } + : { + some: \\"eeeeeeeeeeeeven looooooooooooooooooooooooooooooonger\\", + object: \\"with\\", + lots: \\"of\\", + stuff + }; +" +`; diff --git a/tests/ternaries/jsfmt.spec.js b/tests/ternaries/jsfmt.spec.js index 1ec983a6b..9a1c5daa6 100644 --- a/tests/ternaries/jsfmt.spec.js +++ b/tests/ternaries/jsfmt.spec.js @@ -1,2 +1,5 @@ run_spec(__dirname); run_spec(__dirname, { tabWidth: 4 }); + +run_spec(__dirname, {parser: 'typescript'}); +run_spec(__dirname, { parser: 'typescript', tabWidth: 4 }); \ No newline at end of file diff --git a/tests/trailing_comma/__snapshots__/jsfmt.spec.js.snap b/tests/trailing_comma/__snapshots__/jsfmt.spec.js.snap index d8964afae..dc2d9623a 100644 --- a/tests/trailing_comma/__snapshots__/jsfmt.spec.js.snap +++ b/tests/trailing_comma/__snapshots__/jsfmt.spec.js.snap @@ -117,6 +117,123 @@ function send_single_email( " `; +exports[`es5.js 4`] = ` +"function send_single_email( + app, + email_id, + email_address, + subject, + html, + reply_to +) { + send_single_email_implementation( app, + email_id, + email_address, + subject, + html, + reply_to); + return \\"nothing\\"; +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +function send_single_email( + app, + email_id, + email_address, + subject, + html, + reply_to +) { + send_single_email_implementation( + app, + email_id, + email_address, + subject, + html, + reply_to + ); + return \\"nothing\\"; +} +" +`; + +exports[`es5.js 5`] = ` +"function send_single_email( + app, + email_id, + email_address, + subject, + html, + reply_to +) { + send_single_email_implementation( app, + email_id, + email_address, + subject, + html, + reply_to); + return \\"nothing\\"; +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +function send_single_email( + app, + email_id, + email_address, + subject, + html, + reply_to, +) { + send_single_email_implementation( + app, + email_id, + email_address, + subject, + html, + reply_to, + ); + return \\"nothing\\"; +} +" +`; + +exports[`es5.js 6`] = ` +"function send_single_email( + app, + email_id, + email_address, + subject, + html, + reply_to +) { + send_single_email_implementation( app, + email_id, + email_address, + subject, + html, + reply_to); + return \\"nothing\\"; +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +function send_single_email( + app, + email_id, + email_address, + subject, + html, + reply_to +) { + send_single_email_implementation( + app, + email_id, + email_address, + subject, + html, + reply_to + ); + return \\"nothing\\"; +} +" +`; + exports[`function-calls.js 1`] = ` "const a = (param1, param2, param3) => {} @@ -210,6 +327,99 @@ a( " `; +exports[`function-calls.js 4`] = ` +"const a = (param1, param2, param3) => {} + +a('value', 'value2', 'value3'); + +a( + 'a-long-value', + 'a-really-really-long-value', + 'a-really-really-really-long-value', +); + +a('value', 'value2', a('long-nested-value', 'long-nested-value2', 'long-nested-value3')); +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +const a = (param1, param2, param3) => {}; + +a(\\"value\\", \\"value2\\", \\"value3\\"); + +a( + \\"a-long-value\\", + \\"a-really-really-long-value\\", + \\"a-really-really-really-long-value\\" +); + +a( + \\"value\\", + \\"value2\\", + a(\\"long-nested-value\\", \\"long-nested-value2\\", \\"long-nested-value3\\") +); +" +`; + +exports[`function-calls.js 5`] = ` +"const a = (param1, param2, param3) => {} + +a('value', 'value2', 'value3'); + +a( + 'a-long-value', + 'a-really-really-long-value', + 'a-really-really-really-long-value', +); + +a('value', 'value2', a('long-nested-value', 'long-nested-value2', 'long-nested-value3')); +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +const a = (param1, param2, param3) => {}; + +a(\\"value\\", \\"value2\\", \\"value3\\"); + +a( + \\"a-long-value\\", + \\"a-really-really-long-value\\", + \\"a-really-really-really-long-value\\", +); + +a( + \\"value\\", + \\"value2\\", + a(\\"long-nested-value\\", \\"long-nested-value2\\", \\"long-nested-value3\\"), +); +" +`; + +exports[`function-calls.js 6`] = ` +"const a = (param1, param2, param3) => {} + +a('value', 'value2', 'value3'); + +a( + 'a-long-value', + 'a-really-really-long-value', + 'a-really-really-really-long-value', +); + +a('value', 'value2', a('long-nested-value', 'long-nested-value2', 'long-nested-value3')); +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +const a = (param1, param2, param3) => {}; + +a(\\"value\\", \\"value2\\", \\"value3\\"); + +a( + \\"a-long-value\\", + \\"a-really-really-long-value\\", + \\"a-really-really-really-long-value\\" +); + +a( + \\"value\\", + \\"value2\\", + a(\\"long-nested-value\\", \\"long-nested-value2\\", \\"long-nested-value3\\") +); +" +`; + exports[`object.js 1`] = ` "const a = { b: true, @@ -351,6 +561,147 @@ const aLong = { " `; +exports[`object.js 4`] = ` +"const a = { + b: true, + c: { + c1: 'hello' + }, + d: false +}; + +const aLong = { + bHasALongName: 'a-long-value', + cHasALongName: { + c1: 'a-really-long-value', + c2: 'a-really-really-long-value', + }, + dHasALongName: 'a-long-value-too' +}; + +const aLong = { + dHasALongName: 'a-long-value-too', + eHasABooleanExpression: a === a, +}; +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +const a = { + b: true, + c: { + c1: \\"hello\\" + }, + d: false +}; + +const aLong = { + bHasALongName: \\"a-long-value\\", + cHasALongName: { + c1: \\"a-really-long-value\\", + c2: \\"a-really-really-long-value\\" + }, + dHasALongName: \\"a-long-value-too\\" +}; + +const aLong = { + dHasALongName: \\"a-long-value-too\\", + eHasABooleanExpression: a === a +}; +" +`; + +exports[`object.js 5`] = ` +"const a = { + b: true, + c: { + c1: 'hello' + }, + d: false +}; + +const aLong = { + bHasALongName: 'a-long-value', + cHasALongName: { + c1: 'a-really-long-value', + c2: 'a-really-really-long-value', + }, + dHasALongName: 'a-long-value-too' +}; + +const aLong = { + dHasALongName: 'a-long-value-too', + eHasABooleanExpression: a === a, +}; +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +const a = { + b: true, + c: { + c1: \\"hello\\", + }, + d: false, +}; + +const aLong = { + bHasALongName: \\"a-long-value\\", + cHasALongName: { + c1: \\"a-really-long-value\\", + c2: \\"a-really-really-long-value\\", + }, + dHasALongName: \\"a-long-value-too\\", +}; + +const aLong = { + dHasALongName: \\"a-long-value-too\\", + eHasABooleanExpression: a === a, +}; +" +`; + +exports[`object.js 6`] = ` +"const a = { + b: true, + c: { + c1: 'hello' + }, + d: false +}; + +const aLong = { + bHasALongName: 'a-long-value', + cHasALongName: { + c1: 'a-really-long-value', + c2: 'a-really-really-long-value', + }, + dHasALongName: 'a-long-value-too' +}; + +const aLong = { + dHasALongName: 'a-long-value-too', + eHasABooleanExpression: a === a, +}; +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +const a = { + b: true, + c: { + c1: \\"hello\\", + }, + d: false, +}; + +const aLong = { + bHasALongName: \\"a-long-value\\", + cHasALongName: { + c1: \\"a-really-long-value\\", + c2: \\"a-really-really-long-value\\", + }, + dHasALongName: \\"a-long-value-too\\", +}; + +const aLong = { + dHasALongName: \\"a-long-value-too\\", + eHasABooleanExpression: a === a, +}; +" +`; + exports[`trailing_whitespace.js 1`] = ` "let example = [ 'FOO', @@ -578,3 +929,231 @@ function supersupersupersuperLongF( } " `; + +exports[`trailing_whitespace.js 4`] = ` +"let example = [ + 'FOO', + 'BAR', + // Comment +]; + +foo({}, + // Comment +); + +o = { + state, + // Comment +}; + +o = { + state, + + // Comment +}; + +function supersupersupersuperLongF( + supersupersupersuperLongA, + supersupersupersuperLongB + // Comment +) { + a +} +function supersupersupersuperLongF( + supersupersupersuperLongA, + supersupersupersuperLongB, + // Comment +) { + a +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +let example = [ + \\"FOO\\", + \\"BAR\\" + // Comment +]; + +foo( + {} + // Comment +); + +o = { + state + // Comment +}; + +o = { + state + + // Comment +}; + +function supersupersupersuperLongF( + supersupersupersuperLongA, + supersupersupersuperLongB +) // Comment +{ + a; +} +function supersupersupersuperLongF( + supersupersupersuperLongA, + supersupersupersuperLongB +) // Comment +{ + a; +} +" +`; + +exports[`trailing_whitespace.js 5`] = ` +"let example = [ + 'FOO', + 'BAR', + // Comment +]; + +foo({}, + // Comment +); + +o = { + state, + // Comment +}; + +o = { + state, + + // Comment +}; + +function supersupersupersuperLongF( + supersupersupersuperLongA, + supersupersupersuperLongB + // Comment +) { + a +} +function supersupersupersuperLongF( + supersupersupersuperLongA, + supersupersupersuperLongB, + // Comment +) { + a +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +let example = [ + \\"FOO\\", + \\"BAR\\", + // Comment +]; + +foo( + {}, + // Comment +); + +o = { + state, + // Comment +}; + +o = { + state, + + // Comment +}; + +function supersupersupersuperLongF( + supersupersupersuperLongA, + supersupersupersuperLongB, +) // Comment +{ + a; +} +function supersupersupersuperLongF( + supersupersupersuperLongA, + supersupersupersuperLongB, +) // Comment +{ + a; +} +" +`; + +exports[`trailing_whitespace.js 6`] = ` +"let example = [ + 'FOO', + 'BAR', + // Comment +]; + +foo({}, + // Comment +); + +o = { + state, + // Comment +}; + +o = { + state, + + // Comment +}; + +function supersupersupersuperLongF( + supersupersupersuperLongA, + supersupersupersuperLongB + // Comment +) { + a +} +function supersupersupersuperLongF( + supersupersupersuperLongA, + supersupersupersuperLongB, + // Comment +) { + a +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +let example = [ + \\"FOO\\", + \\"BAR\\", + // Comment +]; + +foo( + {} + // Comment +); + +o = { + state, + // Comment +}; + +o = { + state, + + // Comment +}; + +function supersupersupersuperLongF( + supersupersupersuperLongA, + supersupersupersuperLongB +) // Comment +{ + a; +} +function supersupersupersuperLongF( + supersupersupersuperLongA, + supersupersupersuperLongB +) // Comment +{ + a; +} +" +`; diff --git a/tests/trailing_comma/jsfmt.spec.js b/tests/trailing_comma/jsfmt.spec.js index 8d420a89b..340e6fc24 100644 --- a/tests/trailing_comma/jsfmt.spec.js +++ b/tests/trailing_comma/jsfmt.spec.js @@ -1,3 +1,7 @@ run_spec(__dirname); run_spec(__dirname, { trailingComma: "all" }); run_spec(__dirname, { trailingComma: "es5" }); +// +run_spec(__dirname, {parser: 'typescript'}); +run_spec(__dirname, { parser: 'typescript', trailingComma: "all" }); +run_spec(__dirname, { parser: 'typescript', trailingComma: "es5" }); diff --git a/tests/try/__snapshots__/jsfmt.spec.js.snap b/tests/try/__snapshots__/jsfmt.spec.js.snap index 54f365553..77187de16 100644 --- a/tests/try/__snapshots__/jsfmt.spec.js.snap +++ b/tests/try/__snapshots__/jsfmt.spec.js.snap @@ -21,6 +21,27 @@ try { " `; +exports[`empty.js 2`] = ` +"try { +} catch (e) { +} +finally { +} + +try { +} catch (e) { +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +try { +} catch (e) { +} finally { +} + +try { +} catch (e) {} +" +`; + exports[`try.js 1`] = ` "try /* missing comment */ @@ -33,3 +54,16 @@ try { } " `; + +exports[`try.js 2`] = ` +"try +/* missing comment */ +{;} +finally {} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +try { + /* missing comment */ +} finally { +} +" +`; diff --git a/tests/try/jsfmt.spec.js b/tests/try/jsfmt.spec.js index 989047bcc..1161d7bfb 100644 --- a/tests/try/jsfmt.spec.js +++ b/tests/try/jsfmt.spec.js @@ -1 +1,2 @@ run_spec(__dirname); +run_spec(__dirname, {parser: 'typescript'}); \ No newline at end of file diff --git a/tests/unary/__snapshots__/jsfmt.spec.js.snap b/tests/unary/__snapshots__/jsfmt.spec.js.snap index ff9113c2e..1868258ab 100644 --- a/tests/unary/__snapshots__/jsfmt.spec.js.snap +++ b/tests/unary/__snapshots__/jsfmt.spec.js.snap @@ -13,6 +13,19 @@ state = { " `; +exports[`object.js 2`] = ` +"state = { + // students + hoverColumn: -1 +}; +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +state = { + // students + hoverColumn: -1 +}; +" +`; + exports[`series.js 1`] = ` "1 + ++x; 1 + x++; @@ -51,3 +64,42 @@ x-- - 1; --x - 1; " `; + +exports[`series.js 2`] = ` +"1 + ++x; +1 + x++; + ++ ++x; ++ x++; + +x++ + 1; +++x + 1; + +1 - --x; +1 - x--; + +- --x; +- x--; + +x-- - 1; +--x - 1; +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +1 + ++x; +1 + x++; + ++(++x); ++x++; + +x++ + 1; +++x + 1; + +1 - --x; +1 - x--; + +-(--x); +-x--; + +x-- - 1; +--x - 1; +" +`; diff --git a/tests/unary/jsfmt.spec.js b/tests/unary/jsfmt.spec.js index 989047bcc..1161d7bfb 100644 --- a/tests/unary/jsfmt.spec.js +++ b/tests/unary/jsfmt.spec.js @@ -1 +1,2 @@ run_spec(__dirname); +run_spec(__dirname, {parser: 'typescript'}); \ No newline at end of file diff --git a/tests/unary_expression/__snapshots__/jsfmt.spec.js.snap b/tests/unary_expression/__snapshots__/jsfmt.spec.js.snap index 3fceaa163..d23cc4c30 100644 --- a/tests/unary_expression/__snapshots__/jsfmt.spec.js.snap +++ b/tests/unary_expression/__snapshots__/jsfmt.spec.js.snap @@ -20,3 +20,24 @@ x * +y; +x * y; " `; + +exports[`urnary_expression.js 2`] = ` +"!!x +x++ +x--; +-+1; +x + + + + 1; +x + (+ (+ (+ 1))) +x * +y; ++x * y; +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!x; +x++; +x--; +-+1; +x + +(+(+1)); +x + +(+(+1)); +x * +y; ++x * y; +" +`; diff --git a/tests/unary_expression/jsfmt.spec.js b/tests/unary_expression/jsfmt.spec.js index 989047bcc..1161d7bfb 100644 --- a/tests/unary_expression/jsfmt.spec.js +++ b/tests/unary_expression/jsfmt.spec.js @@ -1 +1,2 @@ run_spec(__dirname); +run_spec(__dirname, {parser: 'typescript'}); \ No newline at end of file diff --git a/tests/update_expression/__snapshots__/jsfmt.spec.js.snap b/tests/update_expression/__snapshots__/jsfmt.spec.js.snap index ee0cc47f6..1d0217054 100644 --- a/tests/update_expression/__snapshots__/jsfmt.spec.js.snap +++ b/tests/update_expression/__snapshots__/jsfmt.spec.js.snap @@ -12,3 +12,16 @@ new (r++)(); const uuid = String(this._uuidCounter++); " `; + +exports[`update_expression.js 2`] = ` +"(this.x++).toString() +new (r++); +(x++)(); +const uuid = String(this._uuidCounter++); +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +(this.x++).toString(); +new (r++)(); +(x++)(); +const uuid = String(this._uuidCounter++); +" +`; diff --git a/tests/update_expression/jsfmt.spec.js b/tests/update_expression/jsfmt.spec.js index 989047bcc..1161d7bfb 100644 --- a/tests/update_expression/jsfmt.spec.js +++ b/tests/update_expression/jsfmt.spec.js @@ -1 +1,2 @@ run_spec(__dirname); +run_spec(__dirname, {parser: 'typescript'}); \ No newline at end of file diff --git a/tests/while/__snapshots__/jsfmt.spec.js.snap b/tests/while/__snapshots__/jsfmt.spec.js.snap index 6c6ff4bbe..11d7214bb 100644 --- a/tests/while/__snapshots__/jsfmt.spec.js.snap +++ b/tests/while/__snapshots__/jsfmt.spec.js.snap @@ -20,3 +20,24 @@ while ( } " `; + +exports[`indent.js 2`] = ` +"if (someVeryLongStringA && someVeryLongStringB && someVeryLongStringC && someVeryLongStringD) {} +while (someVeryLongStringA && someVeryLongStringB && someVeryLongStringC && someVeryLongStringD) {} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +if ( + someVeryLongStringA && + someVeryLongStringB && + someVeryLongStringC && + someVeryLongStringD +) { +} +while ( + someVeryLongStringA && + someVeryLongStringB && + someVeryLongStringC && + someVeryLongStringD +) { +} +" +`; diff --git a/tests/while/jsfmt.spec.js b/tests/while/jsfmt.spec.js index 989047bcc..1161d7bfb 100644 --- a/tests/while/jsfmt.spec.js +++ b/tests/while/jsfmt.spec.js @@ -1 +1,2 @@ run_spec(__dirname); +run_spec(__dirname, {parser: 'typescript'}); \ No newline at end of file diff --git a/tests/windows/__snapshots__/jsfmt.spec.js.snap b/tests/windows/__snapshots__/jsfmt.spec.js.snap index 5892fe8ee..6b0016a15 100644 --- a/tests/windows/__snapshots__/jsfmt.spec.js.snap +++ b/tests/windows/__snapshots__/jsfmt.spec.js.snap @@ -14,3 +14,18 @@ line; endings; " `; + +exports[`line-ending.js 2`] = ` +"this; +has; +windows; +line; +endings; +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +this; +has; +windows; +line; +endings; +" +`; diff --git a/tests/windows/jsfmt.spec.js b/tests/windows/jsfmt.spec.js index 989047bcc..1161d7bfb 100644 --- a/tests/windows/jsfmt.spec.js +++ b/tests/windows/jsfmt.spec.js @@ -1 +1,2 @@ run_spec(__dirname); +run_spec(__dirname, {parser: 'typescript'}); \ No newline at end of file diff --git a/tests/yield/__snapshots__/jsfmt.spec.js.snap b/tests/yield/__snapshots__/jsfmt.spec.js.snap index b76a92b37..f2dee0e07 100644 --- a/tests/yield/__snapshots__/jsfmt.spec.js.snap +++ b/tests/yield/__snapshots__/jsfmt.spec.js.snap @@ -42,3 +42,46 @@ async function f() { } " `; + +exports[`conditional.js 2`] = ` +"function* f() { + a = (yield) ? 1 : 1; + a = yield 1 ? 1 : 1; + a = (yield 1) ? 1 : 1; + a = 1 ? yield : yield; + a = 1 ? yield 1 : yield 1; +} + +function* f() { + a = yield* 1 ? 1 : 1; + a = (yield* 1) ? 1 : 1; + a = 1 ? yield* 1 : yield* 1; +} + +async function f() { + a = await 1 ? 1 : 1; + a = (await 1) ? 1 : 1; + a = 1 ? await 1 : await 1; +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +function* f() { + a = (yield) ? 1 : 1; + a = yield 1 ? 1 : 1; + a = (yield 1) ? 1 : 1; + a = 1 ? yield : yield; + a = 1 ? yield 1 : yield 1; +} + +function* f() { + a = yield* 1 ? 1 : 1; + a = (yield* 1) ? 1 : 1; + a = 1 ? yield* 1 : yield* 1; +} + +async function f() { + a = (await 1) ? 1 : 1; + a = (await 1) ? 1 : 1; + a = 1 ? await 1 : await 1; +} +" +`; diff --git a/tests/yield/jsfmt.spec.js b/tests/yield/jsfmt.spec.js index 939578260..551601bd1 100644 --- a/tests/yield/jsfmt.spec.js +++ b/tests/yield/jsfmt.spec.js @@ -1 +1,2 @@ run_spec(__dirname, {parser: 'babylon'}); +run_spec(__dirname, {parser: 'typescript'}); \ No newline at end of file diff --git a/yarn.lock b/yarn.lock index 38a64355b..35ce20180 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2,10 +2,6 @@ # yarn lockfile v1 -"@comandeer/babel-plugin-banner@^1.0.0": - version "1.0.0" - resolved "https://registry.yarnpkg.com/@comandeer/babel-plugin-banner/-/babel-plugin-banner-1.0.0.tgz#40bcce0bbee084b5b02545a33635d053c248356f" - abab@^1.0.3: version "1.0.3" resolved "https://registry.yarnpkg.com/abab/-/abab-1.0.3.tgz#b81de5f7274ec4e756d797cd834f303642724e5d" @@ -151,7 +147,7 @@ babel-code-frame@6.22.0, babel-code-frame@^6.20.0: esutils "^2.0.2" js-tokens "^3.0.0" -babel-core@^6.0.0, babel-core@^6.18.0, babel-core@^6.21.0: +babel-core@^6.0.0, babel-core@^6.18.0: version "6.21.0" resolved "https://registry.yarnpkg.com/babel-core/-/babel-core-6.21.0.tgz#75525480c21c803f826ef3867d22c19f080a3724" dependencies: @@ -187,30 +183,6 @@ babel-generator@^6.18.0, babel-generator@^6.21.0: lodash "^4.2.0" source-map "^0.5.0" -babel-helper-evaluate-path@^0.0.3: - version "0.0.3" - resolved "https://registry.yarnpkg.com/babel-helper-evaluate-path/-/babel-helper-evaluate-path-0.0.3.tgz#1d103ac9d4a59e5d431842212f151785f7ac547b" - -babel-helper-flip-expressions@^0.0.1: - version "0.0.1" - resolved "https://registry.yarnpkg.com/babel-helper-flip-expressions/-/babel-helper-flip-expressions-0.0.1.tgz#c2ba1599426e7928333fd5c08eee6cdf8328c848" - -babel-helper-is-nodes-equiv@^0.0.1: - version "0.0.1" - resolved "https://registry.yarnpkg.com/babel-helper-is-nodes-equiv/-/babel-helper-is-nodes-equiv-0.0.1.tgz#34e9b300b1479ddd98ec77ea0bbe9342dfe39684" - -babel-helper-is-void-0@^0.0.1: - version "0.0.1" - resolved "https://registry.yarnpkg.com/babel-helper-is-void-0/-/babel-helper-is-void-0-0.0.1.tgz#ed74553b883e68226ae45f989a99b02c190f105a" - -babel-helper-remove-or-void@^0.0.1: - version "0.0.1" - resolved "https://registry.yarnpkg.com/babel-helper-remove-or-void/-/babel-helper-remove-or-void-0.0.1.tgz#f602790e465acf2dfbe84fb3dd210c43a2dd7262" - -babel-helper-to-multiple-sequence-expressions@^0.0.2: - version "0.0.2" - resolved "https://registry.yarnpkg.com/babel-helper-to-multiple-sequence-expressions/-/babel-helper-to-multiple-sequence-expressions-0.0.2.tgz#07d5d2e674aa62962ac9e0000b539920c301c4b9" - babel-helpers@^6.16.0: version "6.16.0" resolved "https://registry.yarnpkg.com/babel-helpers/-/babel-helpers-6.16.0.tgz#1095ec10d99279460553e67eb3eee9973d3867e3" @@ -244,128 +216,6 @@ babel-plugin-jest-hoist@^19.0.0: version "19.0.0" resolved "https://registry.yarnpkg.com/babel-plugin-jest-hoist/-/babel-plugin-jest-hoist-19.0.0.tgz#4ae2a04ea612a6e73651f3fde52c178991304bea" -babel-plugin-minify-constant-folding@^0.0.3: - version "0.0.3" - resolved "https://registry.yarnpkg.com/babel-plugin-minify-constant-folding/-/babel-plugin-minify-constant-folding-0.0.3.tgz#a511e839562489811987a7a503c43c312c40138a" - dependencies: - babel-helper-evaluate-path "^0.0.3" - -babel-plugin-minify-dead-code-elimination@^0.1.1: - version "0.1.1" - resolved "https://registry.yarnpkg.com/babel-plugin-minify-dead-code-elimination/-/babel-plugin-minify-dead-code-elimination-0.1.1.tgz#1a0133fcd06c7fa477b01c193ba3213c8944ff01" - dependencies: - babel-helper-remove-or-void "^0.0.1" - lodash.some "^4.6.0" - -babel-plugin-minify-flip-comparisons@^0.0.1: - version "0.0.1" - resolved "https://registry.yarnpkg.com/babel-plugin-minify-flip-comparisons/-/babel-plugin-minify-flip-comparisons-0.0.1.tgz#679f4493a692afc705c4b79fde1dadb535c4eb08" - dependencies: - babel-helper-is-void-0 "^0.0.1" - -babel-plugin-minify-guarded-expressions@^0.0.3: - version "0.0.3" - resolved "https://registry.yarnpkg.com/babel-plugin-minify-guarded-expressions/-/babel-plugin-minify-guarded-expressions-0.0.3.tgz#6da1caa0b6abda964647377bd5e19afdbf91cae8" - dependencies: - babel-helper-flip-expressions "^0.0.1" - -babel-plugin-minify-infinity@^0.0.3: - version "0.0.3" - resolved "https://registry.yarnpkg.com/babel-plugin-minify-infinity/-/babel-plugin-minify-infinity-0.0.3.tgz#4cc99b61d12b434ce80ad675103335c589cba9a1" - -babel-plugin-minify-mangle-names@^0.0.5: - version "0.0.5" - resolved "https://registry.yarnpkg.com/babel-plugin-minify-mangle-names/-/babel-plugin-minify-mangle-names-0.0.5.tgz#53e4905de90a215622012cc003c3e0d5bdf18a8a" - -babel-plugin-minify-numeric-literals@^0.0.1: - version "0.0.1" - resolved "https://registry.yarnpkg.com/babel-plugin-minify-numeric-literals/-/babel-plugin-minify-numeric-literals-0.0.1.tgz#9597e6c31154d7daf3744d0bd417c144b275bd53" - -babel-plugin-minify-replace@^0.0.1: - version "0.0.1" - resolved "https://registry.yarnpkg.com/babel-plugin-minify-replace/-/babel-plugin-minify-replace-0.0.1.tgz#5d5aea7cb9899245248d1ee9ce7a2fe556a8facc" - -babel-plugin-minify-simplify@^0.0.5: - version "0.0.5" - resolved "https://registry.yarnpkg.com/babel-plugin-minify-simplify/-/babel-plugin-minify-simplify-0.0.5.tgz#71d1de1993a138282c679aad74060829b2b13ed2" - dependencies: - babel-helper-flip-expressions "^0.0.1" - babel-helper-is-nodes-equiv "^0.0.1" - babel-helper-to-multiple-sequence-expressions "^0.0.2" - -babel-plugin-minify-type-constructors@^0.0.2: - version "0.0.2" - resolved "https://registry.yarnpkg.com/babel-plugin-minify-type-constructors/-/babel-plugin-minify-type-constructors-0.0.2.tgz#4f9a28951e776f31ac11a29cd58cf9eef8b2e292" - dependencies: - babel-helper-is-void-0 "^0.0.1" - -babel-plugin-transform-member-expression-literals@^6.8.0: - version "6.8.0" - resolved "https://registry.yarnpkg.com/babel-plugin-transform-member-expression-literals/-/babel-plugin-transform-member-expression-literals-6.8.0.tgz#718755a70492a895d8f41810afa9998bc09f57b9" - dependencies: - babel-runtime "^6.0.0" - -babel-plugin-transform-merge-sibling-variables@^6.8.0: - version "6.8.0" - resolved "https://registry.yarnpkg.com/babel-plugin-transform-merge-sibling-variables/-/babel-plugin-transform-merge-sibling-variables-6.8.0.tgz#724074e4ef78b601fcf9a34165c972a1b6117e99" - dependencies: - babel-runtime "^6.0.0" - -babel-plugin-transform-minify-booleans@^6.8.0: - version "6.8.0" - resolved "https://registry.yarnpkg.com/babel-plugin-transform-minify-booleans/-/babel-plugin-transform-minify-booleans-6.8.0.tgz#b1a48864a727847696b84eae36fa4d085a54b42b" - dependencies: - babel-runtime "^6.0.0" - -babel-plugin-transform-property-literals@^6.8.0: - version "6.8.0" - resolved "https://registry.yarnpkg.com/babel-plugin-transform-property-literals/-/babel-plugin-transform-property-literals-6.8.0.tgz#a65b2e6e1274d25df0f3a4c5e85bc8f1cdd9e019" - dependencies: - babel-runtime "^6.0.0" - -babel-plugin-transform-regexp-constructors@^0.0.3: - version "0.0.3" - resolved "https://registry.yarnpkg.com/babel-plugin-transform-regexp-constructors/-/babel-plugin-transform-regexp-constructors-0.0.3.tgz#463200d8371a06f077226b967858369211b5cfe3" - -babel-plugin-transform-remove-undefined@^0.0.3: - version "0.0.3" - resolved "https://registry.yarnpkg.com/babel-plugin-transform-remove-undefined/-/babel-plugin-transform-remove-undefined-0.0.3.tgz#34baeb7bde4fc01d5235304ee891e7b6bff00432" - -babel-plugin-transform-simplify-comparison-operators@^6.8.0: - version "6.8.0" - resolved "https://registry.yarnpkg.com/babel-plugin-transform-simplify-comparison-operators/-/babel-plugin-transform-simplify-comparison-operators-6.8.0.tgz#0183d65bfdc54c80d922a3a9b3008e25fa9d32a7" - dependencies: - babel-runtime "^6.0.0" - -babel-plugin-transform-undefined-to-void@^6.8.0: - version "6.8.0" - resolved "https://registry.yarnpkg.com/babel-plugin-transform-undefined-to-void/-/babel-plugin-transform-undefined-to-void-6.8.0.tgz#bc5b6b4908d3b1262170e67cb3963903ddce167e" - dependencies: - babel-runtime "^6.0.0" - -babel-preset-babili@0.0.9: - version "0.0.9" - resolved "https://registry.yarnpkg.com/babel-preset-babili/-/babel-preset-babili-0.0.9.tgz#699f08703ff1c84f4f6c229ffe5662c8f1861bf2" - dependencies: - babel-plugin-minify-constant-folding "^0.0.3" - babel-plugin-minify-dead-code-elimination "^0.1.1" - babel-plugin-minify-flip-comparisons "^0.0.1" - babel-plugin-minify-guarded-expressions "^0.0.3" - babel-plugin-minify-infinity "^0.0.3" - babel-plugin-minify-mangle-names "^0.0.5" - babel-plugin-minify-numeric-literals "^0.0.1" - babel-plugin-minify-replace "^0.0.1" - babel-plugin-minify-simplify "^0.0.5" - babel-plugin-minify-type-constructors "^0.0.2" - babel-plugin-transform-member-expression-literals "^6.8.0" - babel-plugin-transform-merge-sibling-variables "^6.8.0" - babel-plugin-transform-minify-booleans "^6.8.0" - babel-plugin-transform-property-literals "^6.8.0" - babel-plugin-transform-regexp-constructors "^0.0.3" - babel-plugin-transform-remove-undefined "^0.0.3" - babel-plugin-transform-simplify-comparison-operators "^6.8.0" - babel-plugin-transform-undefined-to-void "^6.8.0" - babel-preset-jest@^19.0.0: version "19.0.0" resolved "https://registry.yarnpkg.com/babel-preset-jest/-/babel-preset-jest-19.0.0.tgz#22d67201d02324a195811288eb38294bb3cac396" @@ -1602,9 +1452,15 @@ locate-path@^2.0.0: p-locate "^2.0.0" path-exists "^3.0.0" -lodash.some@^4.6.0: - version "4.6.0" - resolved "https://registry.yarnpkg.com/lodash.some/-/lodash.some-4.6.0.tgz#1bb9f314ef6b8baded13b549169b2a945eb68e4d" +lodash.tostring@^4.0.0: + version "4.1.4" + resolved "https://registry.yarnpkg.com/lodash.tostring/-/lodash.tostring-4.1.4.tgz#560c27d1f8eadde03c2cce198fef5c031d8298fb" + +lodash.unescape@4.0.0: + version "4.0.0" + resolved "https://registry.yarnpkg.com/lodash.unescape/-/lodash.unescape-4.0.0.tgz#36debfc492b81478471ef974cd3783e202eb6cef" + dependencies: + lodash.tostring "^4.0.0" lodash@^4.14.0, lodash@^4.2.0: version "4.17.4" @@ -1747,7 +1603,7 @@ oauth-sign@~0.8.1: version "0.8.2" resolved "https://registry.yarnpkg.com/oauth-sign/-/oauth-sign-0.8.2.tgz#46a6ab7f0aead8deae9ec0565780b7d4efeb9d43" -object-assign@^4.1.0: +object-assign@^4.0.1, object-assign@^4.1.0: version "4.1.0" resolved "https://registry.yarnpkg.com/object-assign/-/object-assign-4.1.0.tgz#7a3b3d0e98063d43f4c03f2e8ae6cd51a86883a0" @@ -2076,14 +1932,6 @@ rollup-plugin-node-resolve@2.0.0: builtin-modules "^1.1.0" resolve "^1.1.6" -rollup-plugin-real-babili@1.0.0-alpha3: - version "1.0.0-alpha3" - resolved "https://registry.yarnpkg.com/rollup-plugin-real-babili/-/rollup-plugin-real-babili-1.0.0-alpha3.tgz#11f7dff284726c18d925da5eb0aff783cc45e305" - dependencies: - "@comandeer/babel-plugin-banner" "^1.0.0" - babel-core "^6.21.0" - babel-preset-babili "0.0.9" - rollup-pluginutils@^1.5.1, rollup-pluginutils@^1.5.2: version "1.5.2" resolved "https://registry.yarnpkg.com/rollup-pluginutils/-/rollup-pluginutils-1.5.2.tgz#1e156e778f94b7255bfa1b3d0178be8f5c552408" @@ -2290,6 +2138,17 @@ type-check@~0.3.2: dependencies: prelude-ls "~1.1.2" +"typescript-eslint-parser@git://github.com/eslint/typescript-eslint-parser.git#215a012ec4d272939fa5a57d0231d22fb7f7a9e0": + version "2.0.0" + resolved "git://github.com/eslint/typescript-eslint-parser.git#215a012ec4d272939fa5a57d0231d22fb7f7a9e0" + dependencies: + lodash.unescape "4.0.0" + object-assign "^4.0.1" + +typescript@2.2.1: + version "2.2.1" + resolved "https://registry.yarnpkg.com/typescript/-/typescript-2.2.1.tgz#4862b662b988a4c8ff691cc7969622d24db76ae9" + uglify-js@^2.6: version "2.7.5" resolved "https://registry.yarnpkg.com/uglify-js/-/uglify-js-2.7.5.tgz#4612c0c7baaee2ba7c487de4904ae122079f2ca8"