From 5743ad3923f8f2231ba1e495975d1fd6a951591f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=B2=20Ribaudo?= Date: Mon, 29 Jun 2020 23:23:36 +0200 Subject: [PATCH] [regression] Don't validate file.comments in `@babel/types` (#11752) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Huáng Jùnliàng --- packages/babel-types/src/definitions/core.js | 6 +++++- packages/babel-types/test/regressions.js | 9 +++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 packages/babel-types/test/regressions.js diff --git a/packages/babel-types/src/definitions/core.js b/packages/babel-types/src/definitions/core.js index 38948a63db..b909c13d39 100644 --- a/packages/babel-types/src/definitions/core.js +++ b/packages/babel-types/src/definitions/core.js @@ -280,7 +280,11 @@ defineType("File", { validate: assertNodeType("Program"), }, comments: { - validate: assertEach(assertNodeType("Comment")), + validate: !process.env.BABEL_TYPES_8_BREAKING + ? Object.assign(() => {}, { + each: { oneOfNodeTypes: ["CommentBlock", "CommentLine"] }, + }) + : assertEach(assertNodeType("CommentBlock", "CommentLine")), optional: true, }, tokens: { diff --git a/packages/babel-types/test/regressions.js b/packages/babel-types/test/regressions.js new file mode 100644 index 0000000000..04c345ba7e --- /dev/null +++ b/packages/babel-types/test/regressions.js @@ -0,0 +1,9 @@ +import * as t from "../lib"; + +describe("regressions", () => { + it("jest .toMatchInlineSnapshot used 'Line' for comments", () => { + expect(() => { + t.file(t.program([]), [{ type: "Line" }]); + }).not.toThrow(); + }); +});