Skip to content

Commit

Permalink
Add new tuple and record tests. Fix old test
Browse files Browse the repository at this point in the history
  • Loading branch information
fisker committed Jul 1, 2020
1 parent be46ef0 commit 1026ac0
Show file tree
Hide file tree
Showing 7 changed files with 101 additions and 7 deletions.
13 changes: 12 additions & 1 deletion src/language-js/parser-babel.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,18 @@ function createParse(parseMethod, ...pluginCombinations) {
babelOptions({ sourceType, extraPlugins })
)
);
} catch (error) {
} catch (_error) {
// babel@7.10.4 throws `undefined`, when parsing
// ```js
// alert(
// <!-- comment
// 'hello world'
// )
// ```
// #8688

const error = _error || { message: "Unknown error" };

throw createError(
// babel error prints (l:c) with cols that are zero indexed
// so we need our custom error
Expand Down
30 changes: 30 additions & 0 deletions tests/js/record/__snapshots__/jsfmt.spec.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,36 @@ assert(rest.c === 3);
================================================================================
`;

exports[`invalid-record-method.js format 1`] = `
====================================options=====================================
parsers: ["babel"]
printWidth: 80
| printWidth
=====================================input======================================
// Invalid, https://github.com/babel/babel/pull/11652/
#{
a() {},
async b() {},
get c() {},
set d(_) {},
*e() {}
}
=====================================output=====================================
// Invalid, https://github.com/babel/babel/pull/11652/
#{
a() {},
async b() {},
get c() {},
set d(_) {},
*e() {},
};
================================================================================
`;

exports[`record.js format 1`] = `
====================================options=====================================
parsers: ["babel"]
Expand Down
9 changes: 9 additions & 0 deletions tests/js/record/invalid-record-method.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// Invalid, https://github.com/babel/babel/pull/11652/

#{
a() {},
async b() {},
get c() {},
set d(_) {},
*e() {}
}
40 changes: 40 additions & 0 deletions tests/js/tuple/__snapshots__/jsfmt.spec.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,32 @@ assert(rest[1] === 3);
================================================================================
`;

exports[`invalid-tuple-holes.js format 1`] = `
====================================options=====================================
parsers: ["babel"]
printWidth: 80
| printWidth
=====================================input======================================
#{
a() {},
async b() {},
get c() {},
set d(_) {},
*e() {}
}
=====================================output=====================================
#{
a() {},
async b() {},
get c() {},
set d(_) {},
*e() {},
};
================================================================================
`;

exports[`syntax.js format 1`] = `
====================================options=====================================
parsers: ["babel"]
Expand Down Expand Up @@ -93,3 +119,17 @@ assert(tuple5 === #[2, 2, 3, 4]);
================================================================================
`;

exports[`tuple-trailing-comma.js format 1`] = `
====================================options=====================================
parsers: ["babel"]
printWidth: 80
| printWidth
=====================================input======================================
#[1,]
=====================================output=====================================
#[1];
================================================================================
`;
7 changes: 7 additions & 0 deletions tests/js/tuple/invalid-tuple-holes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#{
a() {},
async b() {},
get c() {},
set d(_) {},
*e() {}
}
1 change: 1 addition & 0 deletions tests/js/tuple/tuple-trailing-comma.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#[1,]
8 changes: 2 additions & 6 deletions tests/misc/errors/js/__snapshots__/jsfmt.spec.js.snap
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`html-like-comments.js error test 1`] = `
"Unexpected token (3:1)
"Unknown error (0:0)
1 | // Only support HTML-like comment in HTML
2 | alert(
> 3 | <!-- comment
| ^
4 | 'hello world'
5 | )
6 | "
3 | <!-- comment"
`;

exports[`module-attributes.js error test 1`] = `
Expand Down

0 comments on commit 1026ac0

Please sign in to comment.