Skip to content

Commit

Permalink
Fix build
Browse files Browse the repository at this point in the history
  • Loading branch information
fisker committed Mar 16, 2023
1 parent f4641e5 commit e2d03d8
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 14 deletions.
9 changes: 0 additions & 9 deletions src/language-js/parse/postprocess/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,9 @@ const isTsKeywordType = require("../../utils/is-ts-keyword-type.js");
const isTypeCastComment = require("../../utils/is-type-cast-comment.js");
const getLast = require("../../../utils/get-last.js");
const visitNode = require("./visit-node.js");
const { throwErrorForInvalidNodes } = require("./typescript.js");
const throwSyntaxError = require("./throw-syntax-error.js");

function postprocess(ast, options) {
if (
options.parser === "typescript" &&
// decorators or abstract properties
/@|abstract/.test(options.originalText)
) {
throwErrorForInvalidNodes(ast, options);
}

// Keep Babel's non-standard ParenthesizedExpression nodes only if they have Closure-style type cast comments.
if (
options.parser !== "typescript" &&
Expand Down
14 changes: 10 additions & 4 deletions src/language-js/parse/postprocess/typescript.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,17 @@ function throwErrorForInvalidAbstractProperty(tsNode, esTreeNode) {
}
}

function throwErrorForInvalidNodes(ast, options) {
const { esTreeNodeToTSNodeMap, tsNodeToESTreeNodeMap } =
options.tsParseResult;
function throwErrorForInvalidNodes(result, options) {
if (
// decorators or abstract properties
!/@|abstract/.test(options.originalText)
) {
return;
}

const { esTreeNodeToTSNodeMap, tsNodeToESTreeNodeMap } = result;

visitNode(ast, (node) => {
visitNode(result.ast, (node) => {
const tsNode = esTreeNodeToTSNodeMap.get(node);
if (!tsNode) {
return;
Expand Down
4 changes: 3 additions & 1 deletion src/language-js/parse/typescript.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const tryCombinations = require("../../utils/try-combinations.js");
const createParser = require("./utils/create-parser.js");
const replaceHashbang = require("./utils/replace-hashbang.js");
const postprocess = require("./postprocess/index.js");
const { throwErrorForInvalidNodes } = require("./postprocess/typescript.js");

/** @type {import("@typescript-eslint/typescript-estree").TSESTreeOptions} */
const parseOptions = {
Expand Down Expand Up @@ -50,7 +51,8 @@ function parse(text, parsers, options = {}) {
}

options.originalText = text;
options.tsParseResult = result;
throwErrorForInvalidNodes(result, options);

return postprocess(result.ast, options);
}

Expand Down

0 comments on commit e2d03d8

Please sign in to comment.