Files
test-repo/src/parser-include-shebang.js
T
Joseph Frazier 3070884b10 Add shebang comment nodes to Flow/TypeScript ASTs (#1905)
* Add shebang comment nodes to Flow/TypeScript ASTs

Now we handle actually printing the shebang in `printComment`, rather
than lopping it off beforehand and reattaching it afterward, as
suggested in https://github.com/prettier/prettier/pull/1718#issuecomment-303876792

* Dedupe AST shebang-insertion code into helper function
2017-06-02 13:38:15 -07:00

31 lines
505 B
JavaScript

"use strict";
function includeShebang(text, ast) {
if (!text.startsWith("#!")) {
return;
}
const index = text.indexOf("\n");
const shebang = text.slice(2, index);
const comment = {
type: "Line",
value: shebang,
range: [0, index],
loc: {
source: null,
start: {
line: 1,
column: 0
},
end: {
line: 1,
column: index
}
}
};
ast.comments = [comment].concat(ast.comments);
}
module.exports = includeShebang;