Move includeShebang to postprocess (#8650)
* Move `includeShebang` to `postprocess` * Style
This commit is contained in:
1 parent
8f2c951e41
commit
98a2ecb54e
4 files changed
+17
-26
No files matched your search
@@ -1,22 +0,0 @@
|
||||
"use strict";
|
||||
|
||||
const { getShebang } = require("./util");
|
||||
|
||||
function includeShebang(text, ast) {
|
||||
const shebang = getShebang(text);
|
||||
|
||||
if (!shebang) {
|
||||
return;
|
||||
}
|
||||
const index = shebang.length;
|
||||
|
||||
const comment = {
|
||||
type: "Line",
|
||||
value: shebang.slice(2),
|
||||
range: [0, index],
|
||||
};
|
||||
|
||||
ast.comments = [comment].concat(ast.comments);
|
||||
}
|
||||
|
||||
module.exports = includeShebang;
|
||||
@@ -1,7 +1,6 @@
|
||||
"use strict";
|
||||
|
||||
const createError = require("../common/parser-create-error");
|
||||
const includeShebang = require("../common/parser-include-shebang");
|
||||
const { hasPragma } = require("./pragma");
|
||||
const locFns = require("./loc");
|
||||
const postprocess = require("./postprocess");
|
||||
@@ -28,7 +27,6 @@ function parse(text, parsers, opts) {
|
||||
});
|
||||
}
|
||||
|
||||
includeShebang(text, ast);
|
||||
return postprocess(ast, { ...opts, originalText: text });
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
"use strict";
|
||||
|
||||
const createError = require("../common/parser-create-error");
|
||||
const includeShebang = require("../common/parser-include-shebang");
|
||||
const { hasPragma } = require("./pragma");
|
||||
const locFns = require("./loc");
|
||||
const postprocess = require("./postprocess");
|
||||
@@ -30,7 +29,6 @@ function parse(text, parsers, opts) {
|
||||
}
|
||||
}
|
||||
|
||||
includeShebang(text, ast);
|
||||
return postprocess(ast, { ...opts, originalText: text });
|
||||
}
|
||||
|
||||
|
||||
@@ -3,11 +3,16 @@
|
||||
const {
|
||||
getLast,
|
||||
getNextNonSpaceNonCommentCharacter,
|
||||
getShebang,
|
||||
} = require("../common/util");
|
||||
const { composeLoc, locEnd } = require("./loc");
|
||||
const { isTypeCastComment } = require("./comments");
|
||||
|
||||
function postprocess(ast, options) {
|
||||
if (options.parser === "typescript" || options.parser === "flow") {
|
||||
includeShebang(ast, options);
|
||||
}
|
||||
|
||||
// Keep Babel's non-standard ParenthesizedExpression nodes only if they have Closure-style type cast comments.
|
||||
if (options.parser !== "typescript" && options.parser !== "flow") {
|
||||
const startOffsetsOfTypeCastedNodes = new Set();
|
||||
@@ -178,4 +183,16 @@ function rebalanceLogicalTree(node) {
|
||||
});
|
||||
}
|
||||
|
||||
function includeShebang(ast, options) {
|
||||
const shebang = getShebang(options.originalText);
|
||||
|
||||
if (shebang) {
|
||||
ast.comments.unshift({
|
||||
type: "Line",
|
||||
value: shebang.slice(2),
|
||||
range: [0, shebang.length],
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = postprocess;
|
||||
Reference in new issue
Block a user