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 fcc1e26
Show file tree
Hide file tree
Showing 6 changed files with 94 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/language-js/parser-babel.js
Expand Up @@ -82,7 +82,17 @@ function createParse(parseMethod, ...pluginCombinations) {
babelOptions({ sourceType, extraPlugins })
)
);
} catch (error) {
} catch (_error) {
// Babel throws `undefined`, when parsing
// ```js
// alert(
// <!-- comment
// 'hello world'
// )
// ```

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
26 changes: 26 additions & 0 deletions tests/js/record/__snapshots__/jsfmt.spec.js.snap
Expand Up @@ -60,6 +60,32 @@ assert(rest.c === 3);
================================================================================
`;

exports[`invalid-record-method.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[`record.js format 1`] = `
====================================options=====================================
parsers: ["babel"]
Expand Down
9 changes: 9 additions & 0 deletions tests/js/record/invalid-record-method.js
@@ -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
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
@@ -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
@@ -0,0 +1 @@
#[1,]

0 comments on commit fcc1e26

Please sign in to comment.