add allowInterpreterDirective option
MODIFY
packages/@romejs/js-compiler/api/compile.ts
packages/@romejs/js-compiler/api/compile.ts
@@ -48,6 +48,7 @@ export default async function compile(
indent: req.stage === "compileForBundle" ? 1 : 0,
sourceMaps: true,
sourceText,
+ allowInterpreterDirective: false,
},
);

MODIFY
packages/@romejs/js-formatter/Builder.ts
packages/@romejs/js-formatter/Builder.ts
@@ -29,6 +29,7 @@ export type BuilderOptions = {
format?: "pretty" | "compact";
sourceMaps?: boolean;
sourceText?: string;
+ allowInterpreterDirective: boolean;
};
export default class Builder {

MODIFY
packages/@romejs/js-formatter/builders/core/Program.ts
packages/@romejs/js-formatter/builders/core/Program.ts
@@ -18,7 +18,7 @@ export default function Program(builder: Builder, node: Program): Token {
tokens.push(hardline);
}
- if (node.interpreter) {
+ if (node.interpreter && builder.options.allowInterpreterDirective) {
tokens.push(builder.tokenize(node.interpreter, node));
}

MODIFY
packages/@romejs/js-formatter/index.ts
packages/@romejs/js-formatter/index.ts
@@ -18,6 +18,7 @@ export type FormatterOptions = {
comments?: Array<AnyComment>;
sourceMaps?: boolean;
sourceText?: string;
+ allowInterpreterDirective?: boolean,
};
export function formatJS(
@@ -28,6 +29,7 @@ export function formatJS(
sourceMaps = false,
comments,
indent = 0,
+ allowInterpreterDirective = true,
}: FormatterOptions = {},
): PrinterOutput {
const builder = new Builder(
@@ -35,6 +37,7 @@ export function formatJS(
format,
sourceMaps,
typeAnnotations,
+ allowInterpreterDirective,
},
ast.type === "Program" ? ast.comments : comments,
);

MODIFY
packages/@romejs/js-parser/tokenizer/index.ts
packages/@romejs/js-parser/tokenizer/index.ts
@@ -406,14 +406,14 @@ function parseLineComment(parser: JSParser, startSkip: number): { startPos: Posi
}
export function skipLineComment(parser: JSParser, startSkip: number): AnyComment {
- const commentLine = parseLineComment(parser, startSkip);
+ const lineComment = parseLineComment(parser, startSkip);
return pushComment(
parser,
{
block: false,
- text: commentLine.text,
- startPos: commentLine.startPos,
- endPos: commentLine.endPos,
+ text: lineComment.text,
+ startPos: lineComment.startPos,
+ endPos: lineComment.endPos,
},
);
}
@@ -422,11 +422,11 @@ export function skipInterpreterDirective(
parser: JSParser,
startSkip: number,
): InterpreterDirective {
- const commentLine = parseLineComment(parser, startSkip);
- const loc = parser.finishLocAt(commentLine.startPos, commentLine.endPos);
+ const lineComment = parseLineComment(parser, startSkip);
+ const loc = parser.finishLocAt(lineComment.startPos, lineComment.endPos);
return {
type: "InterpreterDirective",
- value: commentLine.text,
+ value: lineComment.text,
loc,
};
}

add allowInterpreterDirective option