diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
commit | 36d22d82aa202bb199967e9512281e9a53db42c9 (patch) | |
tree | 105e8c98ddea1c1e4784a60a5a6410fa416be2de /devtools/client/debugger/src/workers/pretty-print/tests | |
parent | Initial commit. (diff) | |
download | firefox-esr-upstream.tar.xz firefox-esr-upstream.zip |
Adding upstream version 115.7.0esr.upstream/115.7.0esrupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'devtools/client/debugger/src/workers/pretty-print/tests')
-rw-r--r-- | devtools/client/debugger/src/workers/pretty-print/tests/__snapshots__/prettyFast.spec.js.snap | 1974 | ||||
-rw-r--r-- | devtools/client/debugger/src/workers/pretty-print/tests/prettyFast.spec.js | 434 |
2 files changed, 2408 insertions, 0 deletions
diff --git a/devtools/client/debugger/src/workers/pretty-print/tests/__snapshots__/prettyFast.spec.js.snap b/devtools/client/debugger/src/workers/pretty-print/tests/__snapshots__/prettyFast.spec.js.snap new file mode 100644 index 0000000000..498bee267e --- /dev/null +++ b/devtools/client/debugger/src/workers/pretty-print/tests/__snapshots__/prettyFast.spec.js.snap @@ -0,0 +1,1974 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`ASI return 1`] = ` +"function f() { + return + { + } +} +" +`; + +exports[`ASI return 2`] = ` +Array [ + "(1, 0) -> (1, 0)", + "(1, 9) -> (1, 9)", + "(1, 10) -> (1, 10)", + "(1, 11) -> (1, 11)", + "(1, 13) -> (1, 13)", + "(2, 2) -> (2, 13)", + "(3, 2) -> (3, 13)", + "(4, 2) -> (3, 14)", + "(5, 0) -> (4, 11)", +] +`; + +exports[`Arrays 1`] = ` +"var a = [ + 1, + 2, + 3 +]; +" +`; + +exports[`Arrays 2`] = ` +Array [ + "(1, 0) -> (1, 0)", + "(1, 4) -> (1, 4)", + "(1, 6) -> (1, 5)", + "(1, 8) -> (1, 6)", + "(2, 2) -> (1, 7)", + "(2, 3) -> (1, 8)", + "(3, 2) -> (1, 9)", + "(3, 3) -> (1, 10)", + "(4, 2) -> (1, 11)", + "(5, 0) -> (1, 12)", + "(5, 1) -> (1, 13)", +] +`; + +exports[`Arrays and spread operator 1`] = ` +"var a = [ + 1, + ...[ + 2, + 3 + ], + ...[], + 4 +]; +" +`; + +exports[`Arrays and spread operator 2`] = ` +Array [ + "(1, 0) -> (1, 0)", + "(1, 4) -> (1, 4)", + "(1, 6) -> (1, 5)", + "(1, 8) -> (1, 6)", + "(2, 2) -> (1, 7)", + "(2, 3) -> (1, 8)", + "(3, 2) -> (1, 9)", + "(3, 5) -> (1, 12)", + "(4, 4) -> (1, 13)", + "(4, 5) -> (1, 14)", + "(5, 4) -> (1, 15)", + "(6, 2) -> (1, 16)", + "(6, 3) -> (1, 17)", + "(7, 2) -> (1, 18)", + "(7, 5) -> (1, 21)", + "(7, 6) -> (1, 22)", + "(7, 7) -> (1, 23)", + "(8, 2) -> (1, 25)", + "(9, 0) -> (1, 26)", + "(9, 1) -> (1, 27)", +] +`; + +exports[`Binary operators 1`] = ` +"var a = 5 * 30; +var b = 5 >> 3; +" +`; + +exports[`Binary operators 2`] = ` +Array [ + "(1, 0) -> (1, 0)", + "(1, 4) -> (1, 4)", + "(1, 6) -> (1, 5)", + "(1, 8) -> (1, 6)", + "(1, 10) -> (1, 7)", + "(1, 12) -> (1, 8)", + "(1, 14) -> (1, 10)", + "(2, 0) -> (1, 11)", + "(2, 4) -> (1, 15)", + "(2, 6) -> (1, 16)", + "(2, 8) -> (1, 17)", + "(2, 10) -> (1, 18)", + "(2, 13) -> (1, 20)", + "(2, 14) -> (1, 21)", +] +`; + +exports[`Bug 975477 don't move end of line comments to next line 1`] = ` +"switch (request.action) { + case 'show': //$NON-NLS-0$ + if (localStorage.hideicon !== 'true') { //$NON-NLS-0$ + chrome.pageAction.show(sender.tab.id); + } + break; + case 'hide': /*Multiline + Comment */ + break; + default: + console.warn('unknown request'); //$NON-NLS-0$ + // don't respond if you don't understand the message. + return; +} +" +`; + +exports[`Bug 975477 don't move end of line comments to next line 2`] = ` +Array [ + "(1, 0) -> (1, 0)", + "(1, 7) -> (1, 7)", + "(1, 8) -> (1, 8)", + "(1, 15) -> (1, 15)", + "(1, 16) -> (1, 16)", + "(1, 22) -> (1, 22)", + "(1, 24) -> (1, 24)", + "(2, 2) -> (2, 13)", + "(2, 7) -> (2, 18)", + "(2, 13) -> (2, 24)", + "(3, 4) -> (3, 15)", + "(3, 7) -> (3, 18)", + "(3, 8) -> (3, 19)", + "(3, 20) -> (3, 31)", + "(3, 21) -> (3, 32)", + "(3, 30) -> (3, 41)", + "(3, 34) -> (3, 45)", + "(3, 40) -> (3, 51)", + "(3, 42) -> (3, 53)", + "(4, 6) -> (4, 17)", + "(4, 12) -> (4, 23)", + "(4, 13) -> (4, 24)", + "(4, 23) -> (4, 34)", + "(4, 24) -> (4, 35)", + "(4, 28) -> (4, 39)", + "(4, 29) -> (4, 40)", + "(4, 35) -> (4, 46)", + "(4, 36) -> (4, 47)", + "(4, 39) -> (4, 50)", + "(4, 40) -> (4, 51)", + "(4, 42) -> (4, 53)", + "(4, 43) -> (4, 54)", + "(5, 4) -> (5, 15)", + "(6, 4) -> (6, 15)", + "(6, 9) -> (6, 20)", + "(7, 2) -> (7, 13)", + "(7, 7) -> (7, 18)", + "(7, 13) -> (7, 24)", + "(9, 4) -> (9, 15)", + "(9, 9) -> (9, 20)", + "(10, 2) -> (10, 13)", + "(10, 9) -> (10, 20)", + "(11, 4) -> (11, 15)", + "(11, 11) -> (11, 22)", + "(11, 12) -> (11, 23)", + "(11, 16) -> (11, 27)", + "(11, 17) -> (11, 28)", + "(11, 34) -> (11, 45)", + "(11, 35) -> (11, 46)", + "(13, 4) -> (13, 15)", + "(13, 10) -> (13, 21)", + "(14, 0) -> (14, 11)", +] +`; + +exports[`Bug 977082 - space between grouping operator and dot notation 1`] = ` +"JSON.stringify(3).length; +([1, +2, +3]).length; +(new Date()).toLocaleString(); +" +`; + +exports[`Bug 977082 - space between grouping operator and dot notation 2`] = ` +Array [ + "(1, 0) -> (1, 0)", + "(1, 4) -> (1, 4)", + "(1, 5) -> (1, 5)", + "(1, 14) -> (1, 14)", + "(1, 15) -> (1, 15)", + "(1, 16) -> (1, 16)", + "(1, 17) -> (1, 17)", + "(1, 18) -> (1, 18)", + "(1, 24) -> (1, 24)", + "(2, 0) -> (2, 11)", + "(2, 1) -> (2, 12)", + "(2, 2) -> (2, 13)", + "(2, 3) -> (2, 14)", + "(3, 0) -> (2, 15)", + "(3, 1) -> (2, 16)", + "(4, 0) -> (2, 17)", + "(4, 1) -> (2, 18)", + "(4, 2) -> (2, 19)", + "(4, 3) -> (2, 20)", + "(4, 4) -> (2, 21)", + "(4, 10) -> (2, 27)", + "(5, 0) -> (3, 11)", + "(5, 1) -> (3, 12)", + "(5, 5) -> (3, 16)", + "(5, 9) -> (3, 20)", + "(5, 10) -> (3, 21)", + "(5, 11) -> (3, 22)", + "(5, 12) -> (3, 23)", + "(5, 13) -> (3, 24)", + "(5, 27) -> (3, 38)", + "(5, 28) -> (3, 39)", + "(5, 29) -> (3, 40)", +] +`; + +exports[`Bug 1206633 - spaces in for of 1`] = ` +"for (let tab of tabs) { +} +" +`; + +exports[`Bug 1206633 - spaces in for of 2`] = ` +Array [ + "(1, 0) -> (1, 0)", + "(1, 4) -> (1, 4)", + "(1, 5) -> (1, 5)", + "(1, 9) -> (1, 9)", + "(1, 13) -> (1, 13)", + "(1, 16) -> (1, 16)", + "(1, 20) -> (1, 20)", + "(1, 22) -> (1, 22)", + "(2, 0) -> (1, 23)", +] +`; + +exports[`Bug 1261971 - indentation after switch statement 1`] = ` +"{ + switch (x) { + } + if (y) { + } + done(); +} +" +`; + +exports[`Bug 1261971 - indentation after switch statement 2`] = ` +Array [ + "(1, 0) -> (1, 0)", + "(2, 2) -> (1, 1)", + "(2, 9) -> (1, 7)", + "(2, 10) -> (1, 8)", + "(2, 11) -> (1, 9)", + "(2, 13) -> (1, 10)", + "(3, 2) -> (1, 11)", + "(4, 2) -> (1, 12)", + "(4, 5) -> (1, 14)", + "(4, 6) -> (1, 15)", + "(4, 7) -> (1, 16)", + "(4, 9) -> (1, 17)", + "(5, 2) -> (1, 18)", + "(6, 2) -> (1, 19)", + "(6, 6) -> (1, 23)", + "(6, 7) -> (1, 24)", + "(6, 8) -> (1, 25)", + "(7, 0) -> (1, 26)", +] +`; + +exports[`Bug pretty-sure-3 - escaping line and paragraph separators 1`] = ` +"x = '\\\\u2029\\\\u2028'; +" +`; + +exports[`Bug pretty-sure-3 - escaping line and paragraph separators 2`] = ` +Array [ + "(1, 0) -> (1, 0)", + "(1, 2) -> (1, 2)", + "(1, 4) -> (1, 4)", + "(1, 18) -> (1, 18)", +] +`; + +exports[`Bug pretty-sure-4 - escaping null character before digit 1`] = ` +"x = '\\\\x001'; +" +`; + +exports[`Bug pretty-sure-4 - escaping null character before digit 2`] = ` +Array [ + "(1, 0) -> (1, 0)", + "(1, 2) -> (1, 2)", + "(1, 4) -> (1, 4)", + "(1, 11) -> (1, 13)", +] +`; + +exports[`Bug pretty-sure-5 - empty multiline comment shouldn't throw exception 1`] = ` +"{ + /* + */ + return; +} +" +`; + +exports[`Bug pretty-sure-5 - empty multiline comment shouldn't throw exception 2`] = ` +Array [ + "(1, 0) -> (1, 0)", + "(4, 2) -> (4, 13)", + "(4, 8) -> (4, 19)", + "(5, 0) -> (5, 11)", +] +`; + +exports[`Bug pretty-sure-6 - inline comment shouldn't move parenthesis to next line 1`] = ` +"return /* inline comment */ (1 + 1); +" +`; + +exports[`Bug pretty-sure-6 - inline comment shouldn't move parenthesis to next line 2`] = ` +Array [ + "(1, 0) -> (1, 0)", + "(1, 28) -> (1, 28)", + "(1, 29) -> (2, 13)", + "(1, 31) -> (2, 14)", + "(1, 33) -> (2, 15)", + "(1, 34) -> (2, 16)", + "(1, 35) -> (2, 17)", +] +`; + +exports[`Bug pretty-sure-7 - accessing a literal number property requires a space 1`] = ` +"0 .toString() + x.toString(); +" +`; + +exports[`Bug pretty-sure-7 - accessing a literal number property requires a space 2`] = ` +Array [ + "(1, 0) -> (1, 0)", + "(1, 2) -> (1, 2)", + "(1, 3) -> (1, 3)", + "(1, 11) -> (1, 11)", + "(1, 12) -> (1, 12)", + "(1, 14) -> (1, 13)", + "(1, 16) -> (1, 14)", + "(1, 17) -> (1, 15)", + "(1, 18) -> (1, 16)", + "(1, 26) -> (1, 24)", + "(1, 27) -> (1, 25)", + "(1, 28) -> (1, 26)", +] +`; + +exports[`Bug pretty-sure-8 - return and yield only accept arguments when on the same line 1`] = ` +"{ + return + (x) + yield + (x) + yield + * x +} +" +`; + +exports[`Bug pretty-sure-8 - return and yield only accept arguments when on the same line 2`] = ` +Array [ + "(1, 0) -> (1, 0)", + "(2, 2) -> (2, 13)", + "(3, 2) -> (3, 13)", + "(3, 3) -> (3, 14)", + "(3, 4) -> (3, 15)", + "(4, 2) -> (4, 13)", + "(5, 2) -> (5, 13)", + "(5, 3) -> (5, 14)", + "(5, 4) -> (5, 15)", + "(6, 2) -> (6, 13)", + "(7, 2) -> (7, 13)", + "(7, 4) -> (7, 14)", + "(8, 0) -> (8, 11)", +] +`; + +exports[`Bug pretty-sure-9 - accept unary operator at start of file 1`] = ` +"+ 0 +" +`; + +exports[`Bug pretty-sure-9 - accept unary operator at start of file 2`] = ` +Array [ + "(1, 0) -> (1, 0)", + "(1, 2) -> (1, 2)", +] +`; + +exports[`Class extension within a function 1`] = ` +"(function () { + class X extends Y { + constructor() { + } + } +}) () +" +`; + +exports[`Class extension within a function 2`] = ` +Array [ + "(1, 0) -> (1, 0)", + "(1, 1) -> (1, 1)", + "(1, 10) -> (1, 9)", + "(1, 11) -> (1, 10)", + "(1, 13) -> (1, 12)", + "(2, 2) -> (1, 15)", + "(2, 8) -> (1, 21)", + "(2, 10) -> (1, 23)", + "(2, 18) -> (1, 31)", + "(2, 20) -> (1, 33)", + "(3, 4) -> (1, 35)", + "(3, 15) -> (1, 46)", + "(3, 16) -> (1, 47)", + "(3, 18) -> (1, 49)", + "(4, 4) -> (1, 50)", + "(5, 2) -> (1, 52)", + "(6, 0) -> (1, 55)", + "(6, 1) -> (1, 56)", + "(6, 3) -> (1, 57)", + "(6, 4) -> (1, 58)", +] +`; + +exports[`Class handling 1`] = ` +"class Class { + constructor() { + } +} +" +`; + +exports[`Class handling 2`] = ` +Array [ + "(1, 0) -> (1, 0)", + "(1, 6) -> (1, 7)", + "(1, 12) -> (1, 12)", + "(2, 2) -> (1, 13)", + "(2, 13) -> (1, 24)", + "(2, 14) -> (1, 25)", + "(2, 16) -> (1, 26)", + "(3, 2) -> (1, 27)", + "(4, 0) -> (1, 28)", +] +`; + +exports[`Code that relies on ASI 1`] = ` +"var foo = 10 +var bar = 20 +function g() { + a() + b() +} +" +`; + +exports[`Code that relies on ASI 2`] = ` +Array [ + "(1, 0) -> (2, 11)", + "(1, 4) -> (2, 15)", + "(1, 8) -> (2, 19)", + "(1, 10) -> (2, 21)", + "(2, 0) -> (3, 11)", + "(2, 4) -> (3, 15)", + "(2, 8) -> (3, 19)", + "(2, 10) -> (3, 21)", + "(3, 0) -> (4, 11)", + "(3, 9) -> (4, 20)", + "(3, 10) -> (4, 21)", + "(3, 11) -> (4, 22)", + "(3, 13) -> (4, 24)", + "(4, 2) -> (5, 13)", + "(4, 3) -> (5, 14)", + "(4, 4) -> (5, 15)", + "(5, 2) -> (6, 13)", + "(5, 3) -> (6, 14)", + "(5, 4) -> (6, 15)", + "(6, 0) -> (7, 11)", +] +`; + +exports[`Const handling 1`] = ` +"const d = 'yes'; +" +`; + +exports[`Const handling 2`] = ` +Array [ + "(1, 0) -> (1, 0)", + "(1, 6) -> (1, 6)", + "(1, 8) -> (1, 8)", + "(1, 10) -> (1, 10)", + "(1, 15) -> (1, 15)", +] +`; + +exports[`Continue/break statements 1`] = ` +"while (1) { + if (x) { + continue + } + if (y) { + break + } + if (z) { + break foo + } +} +" +`; + +exports[`Continue/break statements 2`] = ` +Array [ + "(1, 0) -> (1, 0)", + "(1, 6) -> (1, 5)", + "(1, 7) -> (1, 6)", + "(1, 8) -> (1, 7)", + "(1, 10) -> (1, 8)", + "(2, 2) -> (1, 9)", + "(2, 5) -> (1, 11)", + "(2, 6) -> (1, 12)", + "(2, 7) -> (1, 13)", + "(2, 9) -> (1, 14)", + "(3, 4) -> (1, 15)", + "(4, 2) -> (1, 23)", + "(5, 2) -> (1, 24)", + "(5, 5) -> (1, 26)", + "(5, 6) -> (1, 27)", + "(5, 7) -> (1, 28)", + "(5, 9) -> (1, 29)", + "(6, 4) -> (1, 30)", + "(7, 2) -> (1, 35)", + "(8, 2) -> (1, 36)", + "(8, 5) -> (1, 38)", + "(8, 6) -> (1, 39)", + "(8, 7) -> (1, 40)", + "(8, 9) -> (1, 41)", + "(9, 4) -> (1, 42)", + "(9, 10) -> (1, 48)", + "(10, 2) -> (1, 51)", + "(11, 0) -> (1, 52)", +] +`; + +exports[`Delete 1`] = ` +"delete obj.prop; +" +`; + +exports[`Delete 2`] = ` +Array [ + "(1, 0) -> (1, 0)", + "(1, 7) -> (1, 7)", + "(1, 10) -> (1, 10)", + "(1, 11) -> (1, 11)", + "(1, 15) -> (1, 15)", +] +`; + +exports[`Do/while loop 1`] = ` +"do { + x +} while (y) +" +`; + +exports[`Do/while loop 2`] = ` +Array [ + "(1, 0) -> (1, 0)", + "(1, 3) -> (1, 2)", + "(2, 2) -> (1, 3)", + "(3, 0) -> (1, 4)", + "(3, 2) -> (1, 5)", + "(3, 8) -> (1, 10)", + "(3, 9) -> (1, 11)", + "(3, 10) -> (1, 12)", +] +`; + +exports[`Dot handling with keywords which are identifier name 1`] = ` +"y.await.break.const.delete.else.return.new.yield = 1.23; +" +`; + +exports[`Dot handling with keywords which are identifier name 2`] = ` +Array [ + "(1, 0) -> (1, 0)", + "(1, 1) -> (1, 1)", + "(1, 2) -> (1, 2)", + "(1, 7) -> (1, 7)", + "(1, 8) -> (1, 8)", + "(1, 13) -> (1, 13)", + "(1, 14) -> (1, 14)", + "(1, 19) -> (1, 19)", + "(1, 20) -> (1, 20)", + "(1, 26) -> (1, 26)", + "(1, 27) -> (1, 27)", + "(1, 31) -> (1, 31)", + "(1, 32) -> (1, 32)", + "(1, 38) -> (1, 38)", + "(1, 39) -> (1, 39)", + "(1, 42) -> (1, 42)", + "(1, 43) -> (1, 43)", + "(1, 49) -> (1, 49)", + "(1, 51) -> (1, 51)", + "(1, 55) -> (1, 55)", +] +`; + +exports[`Dot handling with let which is identifier name 1`] = ` +"y.let.let = 1.23; +" +`; + +exports[`Dot handling with let which is identifier name 2`] = ` +Array [ + "(1, 0) -> (1, 0)", + "(1, 1) -> (1, 1)", + "(1, 2) -> (1, 2)", + "(1, 5) -> (1, 5)", + "(1, 6) -> (1, 6)", + "(1, 10) -> (1, 10)", + "(1, 12) -> (1, 12)", + "(1, 16) -> (1, 16)", +] +`; + +exports[`Empty object/array literals 1`] = ` +"let a = []; +const b = {}; +c = { + ...{}, + d: 42 +}; +for (let x of []) { + for (let y in {}) { + } +} +" +`; + +exports[`Empty object/array literals 2`] = ` +Array [ + "(1, 0) -> (1, 0)", + "(1, 4) -> (1, 4)", + "(1, 6) -> (1, 5)", + "(1, 8) -> (1, 6)", + "(1, 9) -> (1, 7)", + "(1, 10) -> (1, 8)", + "(2, 0) -> (1, 9)", + "(2, 6) -> (1, 15)", + "(2, 8) -> (1, 16)", + "(2, 10) -> (1, 17)", + "(2, 11) -> (1, 18)", + "(2, 12) -> (1, 19)", + "(3, 0) -> (1, 20)", + "(3, 2) -> (1, 21)", + "(3, 4) -> (1, 22)", + "(4, 2) -> (1, 23)", + "(4, 5) -> (1, 26)", + "(4, 6) -> (1, 27)", + "(4, 7) -> (1, 28)", + "(5, 2) -> (1, 29)", + "(5, 3) -> (1, 30)", + "(5, 5) -> (1, 32)", + "(6, 0) -> (1, 34)", + "(6, 1) -> (1, 35)", + "(7, 0) -> (1, 36)", + "(7, 4) -> (1, 39)", + "(7, 5) -> (1, 40)", + "(7, 9) -> (1, 44)", + "(7, 11) -> (1, 46)", + "(7, 14) -> (1, 49)", + "(7, 15) -> (1, 50)", + "(7, 16) -> (1, 51)", + "(7, 18) -> (1, 52)", + "(8, 2) -> (1, 53)", + "(8, 6) -> (1, 56)", + "(8, 7) -> (1, 57)", + "(8, 11) -> (1, 61)", + "(8, 13) -> (1, 63)", + "(8, 16) -> (1, 66)", + "(8, 17) -> (1, 67)", + "(8, 18) -> (1, 68)", + "(8, 20) -> (1, 69)", + "(9, 2) -> (1, 70)", + "(10, 0) -> (1, 71)", +] +`; + +exports[`Escaping backslashes in strings 1`] = ` +"'\\\\\\\\' +" +`; + +exports[`Escaping backslashes in strings 2`] = ` +Array [ + "(1, 0) -> (1, 0)", +] +`; + +exports[`Escaping carriage return in strings 1`] = ` +"'\\\\r' +" +`; + +exports[`Escaping carriage return in strings 2`] = ` +Array [ + "(1, 0) -> (1, 0)", +] +`; + +exports[`Escaping form feed in strings 1`] = ` +"'\\\\f' +" +`; + +exports[`Escaping form feed in strings 2`] = ` +Array [ + "(1, 0) -> (1, 0)", +] +`; + +exports[`Escaping null character in strings 1`] = ` +"'\\\\x00' +" +`; + +exports[`Escaping null character in strings 2`] = ` +Array [ + "(1, 0) -> (1, 0)", +] +`; + +exports[`Escaping tab in strings 1`] = ` +"'\\\\t' +" +`; + +exports[`Escaping tab in strings 2`] = ` +Array [ + "(1, 0) -> (1, 0)", +] +`; + +exports[`Escaping vertical tab in strings 1`] = ` +"'\\\\v' +" +`; + +exports[`Escaping vertical tab in strings 2`] = ` +Array [ + "(1, 0) -> (1, 0)", +] +`; + +exports[`False assignment 1`] = ` +"var foo = false; +" +`; + +exports[`False assignment 2`] = ` +Array [ + "(1, 0) -> (1, 0)", + "(1, 4) -> (1, 4)", + "(1, 8) -> (1, 7)", + "(1, 10) -> (1, 8)", + "(1, 15) -> (1, 13)", +] +`; + +exports[`Fat arrow function 1`] = ` +"const a = () => 42 +addEventListener('click', e => { + return false +}); +const sum = (c, d) => c + d +" +`; + +exports[`Fat arrow function 2`] = ` +Array [ + "(1, 0) -> (2, 6)", + "(1, 6) -> (2, 12)", + "(1, 8) -> (2, 14)", + "(1, 10) -> (2, 16)", + "(1, 11) -> (2, 17)", + "(1, 13) -> (2, 19)", + "(1, 16) -> (2, 22)", + "(2, 0) -> (3, 6)", + "(2, 16) -> (3, 22)", + "(2, 17) -> (3, 23)", + "(2, 24) -> (3, 30)", + "(2, 26) -> (3, 32)", + "(2, 28) -> (3, 34)", + "(2, 31) -> (3, 37)", + "(3, 2) -> (3, 39)", + "(3, 9) -> (3, 46)", + "(4, 0) -> (3, 52)", + "(4, 1) -> (3, 53)", + "(4, 2) -> (3, 54)", + "(5, 0) -> (4, 6)", + "(5, 6) -> (4, 12)", + "(5, 10) -> (4, 16)", + "(5, 12) -> (4, 18)", + "(5, 13) -> (4, 19)", + "(5, 14) -> (4, 20)", + "(5, 16) -> (4, 21)", + "(5, 17) -> (4, 22)", + "(5, 19) -> (4, 24)", + "(5, 22) -> (4, 27)", + "(5, 24) -> (4, 28)", + "(5, 26) -> (4, 29)", +] +`; + +exports[`For loop 1`] = ` +"for (var i = 0; i < n; i++) { + console.log(i); +} +" +`; + +exports[`For loop 2`] = ` +Array [ + "(1, 0) -> (1, 0)", + "(1, 4) -> (1, 4)", + "(1, 5) -> (1, 5)", + "(1, 9) -> (1, 9)", + "(1, 11) -> (1, 11)", + "(1, 13) -> (1, 13)", + "(1, 14) -> (1, 14)", + "(1, 16) -> (1, 16)", + "(1, 18) -> (1, 18)", + "(1, 20) -> (1, 20)", + "(1, 21) -> (1, 21)", + "(1, 23) -> (1, 23)", + "(1, 24) -> (1, 24)", + "(1, 26) -> (1, 26)", + "(1, 28) -> (1, 28)", + "(2, 2) -> (1, 30)", + "(2, 9) -> (1, 37)", + "(2, 10) -> (1, 38)", + "(2, 13) -> (1, 41)", + "(2, 14) -> (1, 42)", + "(2, 15) -> (1, 43)", + "(2, 16) -> (1, 44)", + "(3, 0) -> (1, 46)", +] +`; + +exports[`Function calls 1`] = ` +"var result = func(a, b, c, d); +" +`; + +exports[`Function calls 2`] = ` +Array [ + "(1, 0) -> (1, 0)", + "(1, 4) -> (1, 4)", + "(1, 11) -> (1, 10)", + "(1, 13) -> (1, 11)", + "(1, 17) -> (1, 15)", + "(1, 18) -> (1, 16)", + "(1, 19) -> (1, 17)", + "(1, 21) -> (1, 18)", + "(1, 22) -> (1, 19)", + "(1, 24) -> (1, 20)", + "(1, 25) -> (1, 21)", + "(1, 27) -> (1, 22)", + "(1, 28) -> (1, 23)", + "(1, 29) -> (1, 24)", +] +`; + +exports[`Getter and setter literals 1`] = ` +"var obj = { + get foo() { + return this._foo + }, + set foo(v) { + this._foo = v + } +} +" +`; + +exports[`Getter and setter literals 2`] = ` +Array [ + "(1, 0) -> (1, 0)", + "(1, 4) -> (1, 4)", + "(1, 8) -> (1, 7)", + "(1, 10) -> (1, 8)", + "(2, 2) -> (1, 9)", + "(2, 6) -> (1, 13)", + "(2, 9) -> (1, 16)", + "(2, 10) -> (1, 17)", + "(2, 12) -> (1, 18)", + "(3, 4) -> (1, 19)", + "(3, 11) -> (1, 26)", + "(3, 15) -> (1, 30)", + "(3, 16) -> (1, 31)", + "(4, 2) -> (1, 35)", + "(4, 3) -> (1, 36)", + "(5, 2) -> (1, 37)", + "(5, 6) -> (1, 41)", + "(5, 9) -> (1, 44)", + "(5, 10) -> (1, 45)", + "(5, 11) -> (1, 46)", + "(5, 13) -> (1, 47)", + "(6, 4) -> (1, 48)", + "(6, 8) -> (1, 52)", + "(6, 9) -> (1, 53)", + "(6, 14) -> (1, 57)", + "(6, 16) -> (1, 58)", + "(7, 2) -> (1, 59)", + "(8, 0) -> (1, 60)", +] +`; + +exports[`If/else statement 1`] = ` +"if (c) { + then() +} else { + other() +} +" +`; + +exports[`If/else statement 2`] = ` +Array [ + "(1, 0) -> (1, 0)", + "(1, 3) -> (1, 2)", + "(1, 4) -> (1, 3)", + "(1, 5) -> (1, 4)", + "(1, 7) -> (1, 5)", + "(2, 2) -> (1, 6)", + "(2, 6) -> (1, 10)", + "(2, 7) -> (1, 11)", + "(3, 0) -> (1, 12)", + "(3, 2) -> (1, 13)", + "(3, 7) -> (1, 17)", + "(4, 2) -> (1, 18)", + "(4, 7) -> (1, 23)", + "(4, 8) -> (1, 24)", + "(5, 0) -> (1, 25)", +] +`; + +exports[`If/else without curlies 1`] = ` +"if (c) a else b +" +`; + +exports[`If/else without curlies 2`] = ` +Array [ + "(1, 0) -> (1, 0)", + "(1, 3) -> (1, 2)", + "(1, 4) -> (1, 3)", + "(1, 5) -> (1, 4)", + "(1, 7) -> (1, 6)", + "(1, 9) -> (1, 8)", + "(1, 14) -> (1, 13)", +] +`; + +exports[`Immediately invoked function expression 1`] = ` +"(function () { + thingy() +}()) +" +`; + +exports[`Immediately invoked function expression 2`] = ` +Array [ + "(1, 0) -> (1, 0)", + "(1, 1) -> (1, 1)", + "(1, 10) -> (1, 9)", + "(1, 11) -> (1, 10)", + "(1, 13) -> (1, 11)", + "(2, 2) -> (1, 12)", + "(2, 8) -> (1, 18)", + "(2, 9) -> (1, 19)", + "(3, 0) -> (1, 20)", + "(3, 1) -> (1, 21)", + "(3, 2) -> (1, 22)", + "(3, 3) -> (1, 23)", +] +`; + +exports[`In operator 1`] = ` +"if (foo in bar) { + doThing() +} +" +`; + +exports[`In operator 2`] = ` +Array [ + "(1, 0) -> (1, 0)", + "(1, 3) -> (1, 2)", + "(1, 4) -> (1, 3)", + "(1, 8) -> (1, 7)", + "(1, 11) -> (1, 10)", + "(1, 14) -> (1, 13)", + "(1, 16) -> (1, 14)", + "(2, 2) -> (1, 15)", + "(2, 9) -> (1, 22)", + "(2, 10) -> (1, 23)", + "(3, 0) -> (1, 24)", +] +`; + +exports[`Indented multiline comment 1`] = ` +"function foo() { + /** + * java doc style comment + * more comment + */ + bar(); +} +" +`; + +exports[`Indented multiline comment 2`] = ` +Array [ + "(1, 0) -> (1, 0)", + "(1, 9) -> (1, 9)", + "(1, 12) -> (1, 12)", + "(1, 13) -> (1, 13)", + "(1, 15) -> (1, 15)", + "(6, 2) -> (6, 13)", + "(6, 5) -> (6, 16)", + "(6, 6) -> (6, 17)", + "(6, 7) -> (6, 18)", + "(7, 0) -> (7, 11)", +] +`; + +exports[`Instanceof 1`] = ` +"var a = x instanceof y; +" +`; + +exports[`Instanceof 2`] = ` +Array [ + "(1, 0) -> (1, 0)", + "(1, 4) -> (1, 4)", + "(1, 6) -> (1, 5)", + "(1, 8) -> (1, 6)", + "(1, 10) -> (1, 8)", + "(1, 21) -> (1, 19)", + "(1, 22) -> (1, 20)", +] +`; + +exports[`Let handling with value 1`] = ` +"let d = 'yes'; +" +`; + +exports[`Let handling with value 2`] = ` +Array [ + "(1, 0) -> (1, 0)", + "(1, 4) -> (1, 4)", + "(1, 6) -> (1, 6)", + "(1, 8) -> (1, 8)", + "(1, 13) -> (1, 13)", +] +`; + +exports[`Let handling without value 1`] = ` +"let d; +" +`; + +exports[`Let handling without value 2`] = ` +Array [ + "(1, 0) -> (1, 0)", + "(1, 4) -> (1, 4)", + "(1, 5) -> (1, 5)", +] +`; + +exports[`Long parenthesis 1`] = ` +"if ( + thisIsAVeryLongVariable && + thisIsAnotherOne || + yetAnotherVeryLongVariable +) { + ( + thisIsAnotherOne = thisMayReturnNull() || + 'hi', + thisIsAVeryLongVariable = 42, + yetAnotherVeryLongVariable && + doSomething( + true /* do it well */ , + thisIsAVeryLongVariable, + thisIsAnotherOne, + yetAnotherVeryLongVariable + ) + ) +} +for ( + let thisIsAnotherVeryLongVariable = 0; + i < thisIsAnotherVeryLongVariable.length; + thisIsAnotherVeryLongVariable++ +) { +} +const x = ({ + thisIsAnotherVeryLongPropertyName: 'but should not cause the paren to be a line delimiter' +}) +" +`; + +exports[`Long parenthesis 2`] = ` +Array [ + "(1, 0) -> (2, 6)", + "(1, 3) -> (2, 9)", + "(2, 2) -> (2, 10)", + "(2, 26) -> (2, 34)", + "(3, 2) -> (2, 37)", + "(3, 19) -> (2, 54)", + "(4, 2) -> (2, 57)", + "(5, 0) -> (2, 83)", + "(5, 2) -> (2, 85)", + "(6, 2) -> (3, 8)", + "(7, 4) -> (3, 9)", + "(7, 21) -> (3, 26)", + "(7, 23) -> (3, 28)", + "(7, 40) -> (3, 45)", + "(7, 41) -> (3, 46)", + "(7, 43) -> (3, 48)", + "(8, 4) -> (3, 51)", + "(8, 8) -> (3, 55)", + "(9, 4) -> (3, 57)", + "(9, 28) -> (3, 81)", + "(9, 30) -> (3, 83)", + "(9, 32) -> (3, 85)", + "(10, 4) -> (3, 87)", + "(10, 31) -> (3, 114)", + "(11, 4) -> (3, 117)", + "(11, 15) -> (3, 128)", + "(12, 6) -> (3, 129)", + "(12, 28) -> (3, 150)", + "(13, 6) -> (3, 151)", + "(13, 29) -> (3, 174)", + "(14, 6) -> (3, 176)", + "(14, 22) -> (3, 192)", + "(15, 6) -> (3, 194)", + "(16, 4) -> (3, 220)", + "(17, 2) -> (3, 221)", + "(18, 0) -> (4, 6)", + "(19, 0) -> (5, 6)", + "(19, 4) -> (5, 10)", + "(20, 2) -> (5, 11)", + "(20, 6) -> (5, 15)", + "(20, 36) -> (5, 45)", + "(20, 38) -> (5, 47)", + "(20, 39) -> (5, 48)", + "(21, 2) -> (5, 50)", + "(21, 4) -> (5, 52)", + "(21, 6) -> (5, 54)", + "(21, 35) -> (5, 83)", + "(21, 36) -> (5, 84)", + "(21, 42) -> (5, 90)", + "(22, 2) -> (5, 92)", + "(22, 31) -> (5, 121)", + "(23, 0) -> (5, 123)", + "(23, 2) -> (5, 125)", + "(24, 0) -> (5, 126)", + "(25, 0) -> (6, 6)", + "(25, 6) -> (6, 12)", + "(25, 8) -> (6, 14)", + "(25, 10) -> (6, 16)", + "(25, 11) -> (6, 17)", + "(26, 2) -> (6, 18)", + "(26, 35) -> (6, 51)", + "(26, 37) -> (6, 53)", + "(27, 0) -> (6, 108)", + "(27, 1) -> (6, 109)", +] +`; + +exports[`Multi line comment 1`] = ` +"/* Comment + more comment */ +function foo() { + bar(); +} +" +`; + +exports[`Multi line comment 2`] = ` +Array [ + "(3, 0) -> (4, 4)", + "(3, 9) -> (4, 13)", + "(3, 12) -> (4, 16)", + "(3, 13) -> (4, 17)", + "(3, 15) -> (4, 19)", + "(4, 2) -> (4, 21)", + "(4, 5) -> (4, 24)", + "(4, 6) -> (4, 25)", + "(4, 7) -> (4, 26)", + "(5, 0) -> (4, 28)", +] +`; + +exports[`Multiple single line comments 1`] = ` +"function f() { + // a + // b + // c +} +" +`; + +exports[`Multiple single line comments 2`] = ` +Array [ + "(1, 0) -> (1, 0)", + "(1, 9) -> (1, 9)", + "(1, 10) -> (1, 10)", + "(1, 11) -> (1, 11)", + "(1, 13) -> (1, 13)", + "(5, 0) -> (5, 11)", +] +`; + +exports[`Named class handling 1`] = ` +"let unnamed = class Class { + constructor() { + } +} +" +`; + +exports[`Named class handling 2`] = ` +Array [ + "(1, 0) -> (1, 0)", + "(1, 4) -> (1, 4)", + "(1, 12) -> (1, 11)", + "(1, 14) -> (1, 12)", + "(1, 20) -> (1, 18)", + "(1, 26) -> (1, 23)", + "(2, 2) -> (1, 24)", + "(2, 13) -> (1, 35)", + "(2, 14) -> (1, 36)", + "(2, 16) -> (1, 37)", + "(3, 2) -> (1, 38)", + "(4, 0) -> (1, 39)", +] +`; + +exports[`Nested function 1`] = ` +"function foo() { + function bar() { + debugger; + } + bar(); +} +" +`; + +exports[`Nested function 2`] = ` +Array [ + "(1, 0) -> (1, 0)", + "(1, 9) -> (1, 9)", + "(1, 12) -> (1, 12)", + "(1, 13) -> (1, 13)", + "(1, 15) -> (1, 15)", + "(2, 2) -> (1, 17)", + "(2, 11) -> (1, 26)", + "(2, 14) -> (1, 29)", + "(2, 15) -> (1, 30)", + "(2, 17) -> (1, 32)", + "(3, 4) -> (1, 34)", + "(3, 12) -> (1, 42)", + "(4, 2) -> (1, 44)", + "(5, 2) -> (1, 46)", + "(5, 5) -> (1, 49)", + "(5, 6) -> (1, 50)", + "(5, 7) -> (1, 51)", + "(6, 0) -> (1, 53)", +] +`; + +exports[`New expression 1`] = ` +"var foo = new Foo(); +" +`; + +exports[`New expression 2`] = ` +Array [ + "(1, 0) -> (1, 0)", + "(1, 4) -> (1, 4)", + "(1, 8) -> (1, 7)", + "(1, 10) -> (1, 8)", + "(1, 14) -> (1, 12)", + "(1, 17) -> (1, 15)", + "(1, 18) -> (1, 16)", + "(1, 19) -> (1, 17)", +] +`; + +exports[`Non-ASI function call 1`] = ` +"f() +" +`; + +exports[`Non-ASI function call 2`] = ` +Array [ + "(1, 0) -> (1, 0)", + "(1, 1) -> (2, 11)", + "(1, 2) -> (2, 12)", +] +`; + +exports[`Non-ASI in 1`] = ` +"'x' in foo +" +`; + +exports[`Non-ASI in 2`] = ` +Array [ + "(1, 0) -> (1, 0)", + "(1, 4) -> (2, 11)", + "(1, 7) -> (2, 14)", +] +`; + +exports[`Non-ASI new 1`] = ` +"new F() +" +`; + +exports[`Non-ASI new 2`] = ` +Array [ + "(1, 0) -> (1, 0)", + "(1, 4) -> (2, 11)", + "(1, 5) -> (2, 12)", + "(1, 6) -> (2, 13)", +] +`; + +exports[`Non-ASI property access 1`] = ` +"[ + 1, + 2, + 3 +] +[0] +" +`; + +exports[`Non-ASI property access 2`] = ` +Array [ + "(1, 0) -> (1, 0)", + "(2, 2) -> (1, 1)", + "(2, 3) -> (1, 2)", + "(3, 2) -> (1, 3)", + "(3, 3) -> (1, 4)", + "(4, 2) -> (1, 5)", + "(5, 0) -> (1, 6)", + "(6, 0) -> (2, 11)", + "(6, 1) -> (2, 12)", + "(6, 2) -> (2, 13)", +] +`; + +exports[`Null assignment 1`] = ` +"var i = null; +" +`; + +exports[`Null assignment 2`] = ` +Array [ + "(1, 0) -> (1, 0)", + "(1, 4) -> (1, 4)", + "(1, 6) -> (1, 5)", + "(1, 8) -> (1, 6)", + "(1, 12) -> (1, 10)", +] +`; + +exports[`Objects 1`] = ` +"var o = { + a: 1, + b: 2 +}; +" +`; + +exports[`Objects 2`] = ` +Array [ + "(1, 0) -> (2, 6)", + "(1, 4) -> (2, 10)", + "(1, 6) -> (2, 11)", + "(1, 8) -> (2, 12)", + "(2, 2) -> (2, 13)", + "(2, 3) -> (2, 14)", + "(2, 5) -> (2, 15)", + "(2, 6) -> (2, 16)", + "(3, 2) -> (3, 6)", + "(3, 3) -> (3, 7)", + "(3, 5) -> (3, 8)", + "(4, 0) -> (3, 9)", + "(4, 1) -> (3, 10)", +] +`; + +exports[`Optional chaining parsing support 1`] = ` +"x?.y?.z?.['a']?.check(); +" +`; + +exports[`Optional chaining parsing support 2`] = ` +Array [ + "(1, 0) -> (1, 0)", + "(1, 1) -> (1, 1)", + "(1, 3) -> (1, 3)", + "(1, 4) -> (1, 4)", + "(1, 6) -> (1, 6)", + "(1, 7) -> (1, 7)", + "(1, 9) -> (1, 9)", + "(1, 10) -> (1, 10)", + "(1, 13) -> (1, 13)", + "(1, 14) -> (1, 14)", + "(1, 16) -> (1, 16)", + "(1, 21) -> (1, 21)", + "(1, 22) -> (1, 22)", + "(1, 23) -> (1, 23)", +] +`; + +exports[`Private fields parsing support 1`] = ` +"class MyClass { + constructor(a) { + this.#a = a; + this.#b = Math.random(); + this.ab = this.#getAB(); + } + #a + #b = 'default value' + static #someStaticPrivate + #getA() { + return this.#a; + } + #getAB() { + return this.#getA() + this.#b + } +} +" +`; + +exports[`Private fields parsing support 2`] = ` +Array [ + "(1, 0) -> (2, 6)", + "(1, 6) -> (2, 12)", + "(1, 14) -> (2, 20)", + "(2, 2) -> (3, 8)", + "(2, 13) -> (3, 19)", + "(2, 14) -> (3, 20)", + "(2, 15) -> (3, 21)", + "(2, 17) -> (3, 23)", + "(3, 4) -> (4, 10)", + "(3, 8) -> (4, 14)", + "(3, 9) -> (4, 15)", + "(3, 12) -> (4, 18)", + "(3, 14) -> (4, 20)", + "(3, 15) -> (4, 21)", + "(4, 4) -> (4, 22)", + "(4, 8) -> (4, 26)", + "(4, 9) -> (4, 27)", + "(4, 12) -> (4, 30)", + "(4, 14) -> (4, 32)", + "(4, 18) -> (4, 36)", + "(4, 19) -> (4, 37)", + "(4, 25) -> (4, 43)", + "(4, 26) -> (4, 44)", + "(4, 27) -> (4, 45)", + "(5, 4) -> (4, 46)", + "(5, 8) -> (4, 50)", + "(5, 9) -> (4, 51)", + "(5, 12) -> (4, 54)", + "(5, 14) -> (4, 56)", + "(5, 18) -> (4, 60)", + "(5, 19) -> (4, 61)", + "(5, 25) -> (4, 67)", + "(5, 26) -> (4, 68)", + "(5, 27) -> (4, 69)", + "(6, 2) -> (5, 8)", + "(7, 2) -> (6, 8)", + "(8, 2) -> (7, 8)", + "(8, 5) -> (7, 11)", + "(8, 7) -> (7, 13)", + "(9, 2) -> (8, 8)", + "(9, 9) -> (8, 15)", + "(10, 2) -> (9, 8)", + "(10, 7) -> (9, 13)", + "(10, 8) -> (9, 14)", + "(10, 10) -> (9, 16)", + "(11, 4) -> (10, 10)", + "(11, 11) -> (10, 17)", + "(11, 15) -> (10, 21)", + "(11, 16) -> (10, 22)", + "(11, 18) -> (10, 24)", + "(12, 2) -> (11, 8)", + "(13, 2) -> (12, 8)", + "(13, 8) -> (12, 14)", + "(13, 9) -> (12, 15)", + "(13, 11) -> (12, 17)", + "(14, 4) -> (13, 10)", + "(14, 11) -> (13, 17)", + "(14, 15) -> (13, 21)", + "(14, 16) -> (13, 22)", + "(14, 21) -> (13, 27)", + "(14, 22) -> (13, 28)", + "(14, 24) -> (13, 29)", + "(14, 26) -> (13, 30)", + "(14, 30) -> (13, 34)", + "(14, 31) -> (14, 12)", + "(15, 2) -> (15, 8)", + "(16, 0) -> (16, 6)", +] +`; + +exports[`Regexp 1`] = ` +"var r = /foobar/g; +" +`; + +exports[`Regexp 2`] = ` +Array [ + "(1, 0) -> (1, 0)", + "(1, 4) -> (1, 4)", + "(1, 6) -> (1, 5)", + "(1, 8) -> (1, 6)", + "(1, 17) -> (1, 15)", +] +`; + +exports[`Simple function 1`] = ` +"function foo() { + bar(); +} +" +`; + +exports[`Simple function 2`] = ` +Array [ + "(1, 0) -> (1, 0)", + "(1, 9) -> (1, 9)", + "(1, 12) -> (1, 12)", + "(1, 13) -> (1, 13)", + "(1, 15) -> (1, 15)", + "(2, 2) -> (1, 17)", + "(2, 5) -> (1, 20)", + "(2, 6) -> (1, 21)", + "(2, 7) -> (1, 22)", + "(3, 0) -> (1, 24)", +] +`; + +exports[`Single line comment 1`] = ` +"// Comment +function foo() { + bar(); +} +" +`; + +exports[`Single line comment 2`] = ` +Array [ + "(2, 0) -> (3, 4)", + "(2, 9) -> (3, 13)", + "(2, 12) -> (3, 16)", + "(2, 13) -> (3, 17)", + "(2, 15) -> (3, 19)", + "(3, 2) -> (3, 21)", + "(3, 5) -> (3, 24)", + "(3, 6) -> (3, 25)", + "(3, 7) -> (3, 26)", + "(4, 0) -> (3, 28)", +] +`; + +exports[`Stack-keyword property access 1`] = ` +"foo.a = 1.1; +foo.do.switch.case.default = 2.2; +foo.b = 3.3; +" +`; + +exports[`Stack-keyword property access 2`] = ` +Array [ + "(1, 0) -> (1, 0)", + "(1, 3) -> (1, 3)", + "(1, 4) -> (1, 4)", + "(1, 6) -> (1, 5)", + "(1, 8) -> (1, 6)", + "(1, 11) -> (1, 9)", + "(2, 0) -> (1, 10)", + "(2, 3) -> (1, 13)", + "(2, 4) -> (1, 14)", + "(2, 6) -> (1, 16)", + "(2, 7) -> (1, 17)", + "(2, 13) -> (1, 23)", + "(2, 14) -> (1, 24)", + "(2, 18) -> (1, 28)", + "(2, 19) -> (1, 29)", + "(2, 27) -> (1, 36)", + "(2, 29) -> (1, 37)", + "(2, 32) -> (1, 40)", + "(3, 0) -> (1, 41)", + "(3, 3) -> (1, 44)", + "(3, 4) -> (1, 45)", + "(3, 6) -> (1, 46)", + "(3, 8) -> (1, 47)", + "(3, 11) -> (1, 50)", +] +`; + +exports[`String with quote 1`] = ` +"var foo = '\\\\''; +" +`; + +exports[`String with quote 2`] = ` +Array [ + "(1, 0) -> (1, 0)", + "(1, 4) -> (1, 4)", + "(1, 8) -> (1, 8)", + "(1, 10) -> (1, 10)", + "(1, 14) -> (1, 13)", +] +`; + +exports[`String with semicolon 1`] = ` +"var foo = ';'; +" +`; + +exports[`String with semicolon 2`] = ` +Array [ + "(1, 0) -> (1, 0)", + "(1, 4) -> (1, 4)", + "(1, 8) -> (1, 8)", + "(1, 10) -> (1, 10)", + "(1, 13) -> (1, 13)", +] +`; + +exports[`Subclass handling 1`] = ` +"class Class extends Base { + constructor() { + } +} +" +`; + +exports[`Subclass handling 2`] = ` +Array [ + "(1, 0) -> (1, 0)", + "(1, 6) -> (1, 7)", + "(1, 12) -> (1, 14)", + "(1, 20) -> (1, 23)", + "(1, 25) -> (1, 27)", + "(2, 2) -> (1, 28)", + "(2, 13) -> (1, 39)", + "(2, 14) -> (1, 40)", + "(2, 16) -> (1, 41)", + "(3, 2) -> (1, 42)", + "(4, 0) -> (1, 43)", +] +`; + +exports[`Switch statements 1`] = ` +"switch (x) { + case a: + foo(); + break; + default: + bar() +} +" +`; + +exports[`Switch statements 2`] = ` +Array [ + "(1, 0) -> (1, 0)", + "(1, 7) -> (1, 6)", + "(1, 8) -> (1, 7)", + "(1, 9) -> (1, 8)", + "(1, 11) -> (1, 9)", + "(2, 2) -> (1, 10)", + "(2, 7) -> (1, 15)", + "(2, 8) -> (1, 16)", + "(3, 4) -> (1, 17)", + "(3, 7) -> (1, 20)", + "(3, 8) -> (1, 21)", + "(3, 9) -> (1, 22)", + "(4, 4) -> (1, 23)", + "(4, 9) -> (1, 28)", + "(5, 2) -> (1, 29)", + "(5, 9) -> (1, 36)", + "(6, 4) -> (1, 37)", + "(6, 7) -> (1, 40)", + "(6, 8) -> (1, 41)", + "(7, 0) -> (1, 42)", +] +`; + +exports[`Template literals 1`] = ` +"\`abc\${ JSON.stringify({ + clas: 'testing' +}) }def\`; +{ + a(); +} +" +`; + +exports[`Template literals 2`] = ` +Array [ + "(1, 0) -> (1, 0)", + "(1, 1) -> (1, 1)", + "(1, 4) -> (1, 4)", + "(1, 7) -> (1, 6)", + "(1, 11) -> (1, 10)", + "(1, 12) -> (1, 11)", + "(1, 21) -> (1, 20)", + "(1, 22) -> (1, 21)", + "(2, 2) -> (1, 22)", + "(2, 6) -> (1, 26)", + "(2, 8) -> (1, 28)", + "(3, 0) -> (1, 37)", + "(3, 1) -> (1, 38)", + "(3, 3) -> (1, 39)", + "(3, 4) -> (1, 40)", + "(3, 7) -> (1, 43)", + "(3, 8) -> (1, 44)", + "(4, 0) -> (1, 45)", + "(5, 2) -> (1, 46)", + "(5, 3) -> (1, 47)", + "(5, 4) -> (1, 48)", + "(5, 5) -> (1, 49)", + "(6, 0) -> (1, 50)", +] +`; + +exports[`Ternary operator 1`] = ` +"bar ? baz : bang; +" +`; + +exports[`Ternary operator 2`] = ` +Array [ + "(1, 0) -> (1, 0)", + "(1, 4) -> (1, 3)", + "(1, 6) -> (1, 4)", + "(1, 10) -> (1, 7)", + "(1, 12) -> (1, 8)", + "(1, 16) -> (1, 12)", +] +`; + +exports[`This property access 1`] = ` +"var foo = this.foo; +" +`; + +exports[`This property access 2`] = ` +Array [ + "(1, 0) -> (1, 0)", + "(1, 4) -> (1, 4)", + "(1, 8) -> (1, 7)", + "(1, 10) -> (1, 8)", + "(1, 14) -> (1, 12)", + "(1, 15) -> (1, 13)", + "(1, 18) -> (1, 16)", +] +`; + +exports[`True assignment 1`] = ` +"var foo = true; +" +`; + +exports[`True assignment 2`] = ` +Array [ + "(1, 0) -> (1, 0)", + "(1, 4) -> (1, 4)", + "(1, 8) -> (1, 7)", + "(1, 10) -> (1, 8)", + "(1, 14) -> (1, 12)", +] +`; + +exports[`Try/catch/finally statement 1`] = ` +"try { + dangerous() +} catch (e) { + handle(e) +} finally { + cleanup() +} +" +`; + +exports[`Try/catch/finally statement 2`] = ` +Array [ + "(1, 0) -> (1, 0)", + "(1, 4) -> (1, 3)", + "(2, 2) -> (1, 4)", + "(2, 11) -> (1, 13)", + "(2, 12) -> (1, 14)", + "(3, 0) -> (1, 15)", + "(3, 2) -> (1, 16)", + "(3, 8) -> (1, 21)", + "(3, 9) -> (1, 22)", + "(3, 10) -> (1, 23)", + "(3, 12) -> (1, 24)", + "(4, 2) -> (1, 25)", + "(4, 8) -> (1, 31)", + "(4, 9) -> (1, 32)", + "(4, 10) -> (1, 33)", + "(5, 0) -> (1, 34)", + "(5, 2) -> (1, 35)", + "(5, 10) -> (1, 42)", + "(6, 2) -> (1, 43)", + "(6, 9) -> (1, 50)", + "(6, 10) -> (1, 51)", + "(7, 0) -> (1, 52)", +] +`; + +exports[`Undefined assignment 1`] = ` +"var i = undefined; +" +`; + +exports[`Undefined assignment 2`] = ` +Array [ + "(1, 0) -> (1, 0)", + "(1, 4) -> (1, 4)", + "(1, 6) -> (1, 5)", + "(1, 8) -> (1, 6)", + "(1, 17) -> (1, 15)", +] +`; + +exports[`Unnamed class handling 1`] = ` +"let unnamed = class { + constructor() { + } +} +" +`; + +exports[`Unnamed class handling 2`] = ` +Array [ + "(1, 0) -> (1, 0)", + "(1, 4) -> (1, 4)", + "(1, 12) -> (1, 11)", + "(1, 14) -> (1, 12)", + "(1, 20) -> (1, 17)", + "(2, 2) -> (1, 18)", + "(2, 13) -> (1, 29)", + "(2, 14) -> (1, 30)", + "(2, 16) -> (1, 31)", + "(3, 2) -> (1, 32)", + "(4, 0) -> (1, 33)", +] +`; + +exports[`Void 0 assignment 1`] = ` +"var i = void 0; +" +`; + +exports[`Void 0 assignment 2`] = ` +Array [ + "(1, 0) -> (1, 0)", + "(1, 4) -> (1, 4)", + "(1, 6) -> (1, 5)", + "(1, 8) -> (1, 6)", + "(1, 13) -> (1, 11)", + "(1, 14) -> (1, 12)", +] +`; + +exports[`With statement 1`] = ` +"with (obj) { + crock() +} +" +`; + +exports[`With statement 2`] = ` +Array [ + "(1, 0) -> (1, 0)", + "(1, 5) -> (1, 4)", + "(1, 6) -> (1, 5)", + "(1, 9) -> (1, 8)", + "(1, 11) -> (1, 9)", + "(2, 2) -> (1, 10)", + "(2, 7) -> (1, 15)", + "(2, 8) -> (1, 16)", + "(3, 0) -> (1, 17)", +] +`; + +exports[`for..of loop 1`] = ` +"for (const x of [ + 1, + 2, + 3 +]) { + console.log(x) +} +" +`; + +exports[`for..of loop 2`] = ` +Array [ + "(1, 0) -> (1, 0)", + "(1, 4) -> (1, 4)", + "(1, 5) -> (1, 5)", + "(1, 11) -> (1, 11)", + "(1, 13) -> (1, 13)", + "(1, 16) -> (1, 16)", + "(2, 2) -> (1, 17)", + "(2, 3) -> (1, 18)", + "(3, 2) -> (1, 19)", + "(3, 3) -> (1, 20)", + "(4, 2) -> (1, 21)", + "(5, 0) -> (1, 22)", + "(5, 1) -> (1, 23)", + "(5, 3) -> (1, 25)", + "(6, 2) -> (1, 27)", + "(6, 9) -> (1, 34)", + "(6, 10) -> (1, 35)", + "(6, 13) -> (1, 38)", + "(6, 14) -> (1, 39)", + "(6, 15) -> (1, 40)", + "(7, 0) -> (1, 42)", +] +`; diff --git a/devtools/client/debugger/src/workers/pretty-print/tests/prettyFast.spec.js b/devtools/client/debugger/src/workers/pretty-print/tests/prettyFast.spec.js new file mode 100644 index 0000000000..f1f7a1c635 --- /dev/null +++ b/devtools/client/debugger/src/workers/pretty-print/tests/prettyFast.spec.js @@ -0,0 +1,434 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at <http://mozilla.org/MPL/2.0/>. */ + +/* + * Copyright 2013 Mozilla Foundation and contributors + * Licensed under the New BSD license. See LICENSE.md or: + * http://opensource.org/licenses/BSD-2-Clause + */ +import { prettyFast } from "../pretty-fast"; +import { SourceMapConsumer } from "devtools/client/shared/vendor/source-map/source-map"; + +const cases = [ + { + name: "Simple function", + input: "function foo() { bar(); }", + }, + { + name: "Nested function", + input: "function foo() { function bar() { debugger; } bar(); }", + }, + { + name: "Immediately invoked function expression", + input: "(function(){thingy()}())", + }, + { + name: "Single line comment", + input: ` + // Comment + function foo() { bar(); }`, + }, + { + name: "Multi line comment", + input: ` + /* Comment + more comment */ + function foo() { bar(); } + `, + }, + { name: "Null assignment", input: "var i=null;" }, + { name: "Undefined assignment", input: "var i=undefined;" }, + { name: "Void 0 assignment", input: "var i=void 0;" }, + { + name: "This property access", + input: "var foo=this.foo;\n", + }, + + { + name: "True assignment", + input: "var foo=true;\n", + }, + + { + name: "False assignment", + input: "var foo=false;\n", + }, + + { + name: "For loop", + input: "for (var i = 0; i < n; i++) { console.log(i); }", + }, + + { + name: "for..of loop", + input: "for (const x of [1,2,3]) { console.log(x) }", + }, + + { + name: "String with semicolon", + input: "var foo = ';';\n", + }, + + { + name: "String with quote", + input: 'var foo = "\'";\n', + }, + + { + name: "Function calls", + input: "var result=func(a,b,c,d);", + }, + + { + name: "Regexp", + input: "var r=/foobar/g;", + }, + + { + name: "In operator", + input: "if(foo in bar){doThing()}", + output: "if (foo in bar) {\n" + " doThing()\n" + "}\n", + }, + { + name: "With statement", + input: "with(obj){crock()}", + }, + { + name: "New expression", + input: "var foo=new Foo();", + }, + { + name: "Continue/break statements", + input: "while(1){if(x){continue}if(y){break}if(z){break foo}}", + }, + { + name: "Instanceof", + input: "var a=x instanceof y;", + }, + { + name: "Binary operators", + input: "var a=5*30;var b=5>>3;", + }, + { + name: "Delete", + input: "delete obj.prop;", + }, + + { + name: "Try/catch/finally statement", + input: "try{dangerous()}catch(e){handle(e)}finally{cleanup()}", + }, + { + name: "If/else statement", + input: "if(c){then()}else{other()}", + }, + { + name: "If/else without curlies", + input: "if(c) a else b", + }, + { + name: "Objects", + input: ` + var o={a:1, + b:2};`, + }, + { + name: "Do/while loop", + input: "do{x}while(y)", + }, + { + name: "Arrays", + input: "var a=[1,2,3];", + }, + { + name: "Arrays and spread operator", + input: "var a=[1,...[2,3],...[], 4];", + }, + { + name: "Empty object/array literals", + input: `let a=[];const b={};c={...{},d: 42};for(let x of []){for(let y in {}){}}`, + }, + { + name: "Code that relies on ASI", + input: ` + var foo = 10 + var bar = 20 + function g() { + a() + b() + }`, + }, + { + name: "Ternary operator", + input: "bar?baz:bang;", + }, + { + name: "Switch statements", + input: "switch(x){case a:foo();break;default:bar()}", + }, + + { + name: "Multiple single line comments", + input: `function f() { + // a + // b + // c + }`, + }, + { + name: "Indented multiline comment", + input: `function foo() { + /** + * java doc style comment + * more comment + */ + bar(); + }`, + }, + { + name: "ASI return", + input: `function f() { + return + {} + }`, + }, + { + name: "Non-ASI property access", + input: `[1,2,3] + [0]`, + }, + { + name: "Non-ASI in", + input: `'x' + in foo`, + }, + + { + name: "Non-ASI function call", + input: `f + ()`, + }, + { + name: "Non-ASI new", + input: `new + F()`, + }, + { + name: "Getter and setter literals", + input: "var obj={get foo(){return this._foo},set foo(v){this._foo=v}}", + }, + { + name: "Escaping backslashes in strings", + input: "'\\\\'\n", + }, + { + name: "Escaping carriage return in strings", + input: "'\\r'\n", + }, + { + name: "Escaping tab in strings", + input: "'\\t'\n", + }, + { + name: "Escaping vertical tab in strings", + input: "'\\v'\n", + }, + { + name: "Escaping form feed in strings", + input: "'\\f'\n", + }, + { + name: "Escaping null character in strings", + input: "'\\0'\n", + }, + { + name: "Bug 977082 - space between grouping operator and dot notation", + input: `JSON.stringify(3).length; + ([1,2,3]).length; + (new Date()).toLocaleString();`, + }, + { + name: "Bug 975477 don't move end of line comments to next line", + input: `switch (request.action) { + case 'show': //$NON-NLS-0$ + if (localStorage.hideicon !== 'true') { //$NON-NLS-0$ + chrome.pageAction.show(sender.tab.id); + } + break; + case 'hide': /*Multiline + Comment */ + break; + default: + console.warn('unknown request'); //$NON-NLS-0$ + // don't respond if you don't understand the message. + return; + }`, + }, + { + name: "Const handling", + input: "const d = 'yes';\n", + }, + { + name: "Let handling without value", + input: "let d;\n", + }, + { + name: "Let handling with value", + input: "let d = 'yes';\n", + }, + { + name: "Template literals", + // issue in acorn + input: "`abc${JSON.stringify({clas: 'testing'})}def`;{a();}", + }, + { + name: "Class handling", + input: "class Class{constructor(){}}", + }, + { + name: "Subclass handling", + input: "class Class extends Base{constructor(){}}", + }, + { + name: "Unnamed class handling", + input: "let unnamed=class{constructor(){}}", + }, + { + name: "Named class handling", + input: "let unnamed=class Class{constructor(){}}", + }, + { + name: "Class extension within a function", + input: "(function() { class X extends Y { constructor() {} } })()", + }, + { + name: "Bug 1261971 - indentation after switch statement", + input: "{switch(x){}if(y){}done();}", + }, + { + name: "Bug 1206633 - spaces in for of", + input: "for (let tab of tabs) {}", + }, + { + name: "Bug pretty-sure-3 - escaping line and paragraph separators", + input: "x = '\\u2029\\u2028';", + }, + { + name: "Bug pretty-sure-4 - escaping null character before digit", + input: "x = '\\u00001';", + }, + { + name: "Bug pretty-sure-5 - empty multiline comment shouldn't throw exception", + input: `{ + /* + */ + return; + }`, + }, + { + name: "Bug pretty-sure-6 - inline comment shouldn't move parenthesis to next line", + input: `return /* inline comment */ ( + 1+1);`, + }, + { + name: "Bug pretty-sure-7 - accessing a literal number property requires a space", + input: "0..toString()+x.toString();", + }, + { + name: "Bug pretty-sure-8 - return and yield only accept arguments when on the same line", + input: `{ + return + (x) + yield + (x) + yield + *x + }`, + }, + { + name: "Bug pretty-sure-9 - accept unary operator at start of file", + input: "+ 0", + }, + { + name: "Stack-keyword property access", + input: "foo.a=1.1;foo.do.switch.case.default=2.2;foo.b=3.3;\n", + }, + { + name: "Dot handling with let which is identifier name", + input: "y.let.let = 1.23;\n", + }, + { + name: "Dot handling with keywords which are identifier name", + input: "y.await.break.const.delete.else.return.new.yield = 1.23;\n", + }, + { + name: "Optional chaining parsing support", + input: "x?.y?.z?.['a']?.check();\n", + }, + { + name: "Private fields parsing support", + input: ` + class MyClass { + constructor(a) { + this.#a = a;this.#b = Math.random();this.ab = this.#getAB(); + } + #a + #b = "default value" + static #someStaticPrivate + #getA() { + return this.#a; + } + #getAB() { + return this.#getA()+this. + #b + } + } + `, + }, + { + name: "Long parenthesis", + input: ` + if (thisIsAVeryLongVariable && thisIsAnotherOne || yetAnotherVeryLongVariable) { + (thisIsAnotherOne = thisMayReturnNull() || "hi", thisIsAVeryLongVariable = 42, yetAnotherVeryLongVariable && doSomething(true /* do it well */,thisIsAVeryLongVariable, thisIsAnotherOne, yetAnotherVeryLongVariable)) + } + for (let thisIsAnotherVeryLongVariable = 0; i < thisIsAnotherVeryLongVariable.length; thisIsAnotherVeryLongVariable++) {} + const x = ({thisIsAnotherVeryLongPropertyName: "but should not cause the paren to be a line delimiter"}) + `, + }, + { + name: "Fat arrow function", + input: ` + const a = () => 42 + addEventListener("click", e => { return false }); + const sum = (c,d) => c+d + `, + }, +]; + +const includesOnly = cases.find(({ only }) => only); + +for (const { name, input, only, skip } of cases) { + if ((includesOnly && !only) || skip) { + continue; + } + test(name, async () => { + const actual = prettyFast(input, { + indent: " ", + url: "test.js", + }); + + expect(actual.code).toMatchSnapshot(); + + const smc = await new SourceMapConsumer(actual.map.toJSON()); + const mappings = []; + smc.eachMapping( + ({ generatedColumn, generatedLine, originalColumn, originalLine }) => { + mappings.push( + `(${originalLine}, ${originalColumn}) -> (${generatedLine}, ${generatedColumn})` + ); + } + ); + expect(mappings).toMatchSnapshot(); + }); +} |