Migrate JS language to ES Module (#12342)

This commit is contained in:
fisker Cheung authored and GitHub committed 2022-02-21 15:53:02 +08:00
1 parent c5fd728273
commit 54835025d5
74 files changed
+679 -709

No files matched your search

-1
View File
@@ -177,7 +177,6 @@ module.exports = {
"src/config/**/*.js",
"src/document/**/*.js",
"src/language-html/**/*.js",
"src/language-js/**/*.js",
"src/main/**/*.js",
"src/utils/**/*.js",
"scripts/tools/eslint-plugin-prettier-internal-rules/**/*.js",
+2 -5
View File
@@ -86,10 +86,7 @@ function* getEsbuildOptions(bundle, buildOptions) {
};
// Replace parser getters with `undefined`
for (const file of [
"src/language-html/parsers.js",
"src/language-js/parse/parsers.js",
]) {
for (const file of ["src/language-html/parsers.js"]) {
replaceModule[path.join(PROJECT_ROOT, file)] = EMPTY_MODULE_REPLACEMENT;
}
for (const file of [
@@ -97,7 +94,7 @@ function* getEsbuildOptions(bundle, buildOptions) {
"src/language-graphql/parsers.js",
"src/language-handlebars/parsers.js",
// "src/language-html/parsers.js",
// "src/language-js/parse/parsers.js",
"src/language-js/parse/parsers.js",
"src/language-markdown/parsers.js",
"src/language-yaml/parsers.js",
]) {
+6
View File
@@ -26,6 +26,7 @@ const { require } = createEsmUtils(import.meta);
const parsers = [
{
input: "src/language-js/parse/babel.js",
isEsm: true,
},
{
input: "src/language-js/parse/flow.js",
@@ -33,6 +34,7 @@ const parsers = [
// `flow-parser` use this for `globalThis`, can't work in strictMode
"(function(){return this}())": '(new Function("return this")())',
},
isEsm: true,
},
{
input: "src/language-js/parse/typescript.js",
@@ -94,6 +96,7 @@ const parsers = [
replaceModule: {
[require.resolve("debug")]: require.resolve("./shims/debug.cjs"),
},
isEsm: true,
},
{
input: "src/language-js/parse/acorn-and-espree.js",
@@ -104,15 +107,18 @@ const parsers = [
"const Syntax = ": "const Syntax = undefined && ",
"var visitorKeys = ": "var visitorKeys = undefined && ",
},
isEsm: true,
},
{
input: "src/language-js/parse/meriyah.js",
isEsm: true,
},
{
input: "src/language-js/parse/angular.js",
replace: {
"@angular/compiler/src": "@angular/compiler/esm2015/src",
},
isEsm: true,
},
{
input: "src/language-css/parser-postcss.js",
@@ -26,7 +26,8 @@ export default function esbuildPluginReplaceModule(replacements = {}) {
// Make this work with `@esbuild-plugins/node-modules-polyfill` plugin
if (
!resolveDir &&
namespace === "node-modules-polyfills-commonjs" &&
(namespace === "node-modules-polyfills-commonjs" ||
namespace === "node-modules-polyfills") &&
file
) {
resolveDir = dirname(file);
+6 -4
View File
@@ -1,15 +1,17 @@
import jsPragma from "../language-js/pragma.js";
import {
hasPragma as jsHasPragma,
insertPragma as jsInsertPragma,
} from "../language-js/pragma.js";
import parseFrontMatter from "../utils/front-matter/parse.js";
function hasPragma(text) {
return jsPragma.hasPragma(parseFrontMatter(text).content);
return jsHasPragma(parseFrontMatter(text).content);
}
function insertPragma(text) {
const { frontMatter, content } = parseFrontMatter(text);
return (
(frontMatter ? frontMatter.raw + "\n\n" : "") +
jsPragma.insertPragma(content)
(frontMatter ? frontMatter.raw + "\n\n" : "") + jsInsertPragma(content)
);
}
+2 -4
View File
@@ -1,6 +1,4 @@
"use strict";
const isBlockComment = require("./utils/is-block-comment.js");
import isBlockComment from "./utils/is-block-comment.js";
const ignoredProperties = new Set([
"range",
@@ -212,4 +210,4 @@ function clean(ast, newObj, parent) {
clean.ignoredProperties = ignoredProperties;
module.exports = clean;
export default clean;
+7 -9
View File
@@ -1,6 +1,4 @@
"use strict";
const {
import {
getLast,
hasNewline,
getNextNonSpaceNonCommentCharacterIndexWithStartIndex,
@@ -11,8 +9,8 @@ const {
addDanglingComment,
getNextNonSpaceNonCommentCharacterIndex,
isNonEmptyArray,
} = require("../common/util.js");
const {
} from "../common/util.js";
import {
getFunctionParameters,
isPrettierIgnoreComment,
isJsxNode,
@@ -28,9 +26,9 @@ const {
getComments,
CommentCheckFlags,
markerForIfWithoutBlockAndSameLineComment,
} = require("./utils/index.js");
const { locStart, locEnd } = require("./loc.js");
const isBlockComment = require("./utils/is-block-comment.js");
} from "./utils/index.js";
import { locStart, locEnd } from "./loc.js";
import isBlockComment from "./utils/is-block-comment.js";
/**
* @typedef {import("./types/estree").Node} Node
@@ -1026,7 +1024,7 @@ function willPrintOwnComments(path /*, options */) {
);
}
module.exports = {
export {
handleOwnLineComment,
handleEndOfLineComment,
handleRemainingComment,
+7 -9
View File
@@ -1,14 +1,12 @@
"use strict";
const {
import {
hasComment,
CommentCheckFlags,
isObjectProperty,
} = require("./utils/index.js");
const formatMarkdown = require("./embed/markdown.js");
const formatCss = require("./embed/css.js");
const formatGraphql = require("./embed/graphql.js");
const formatHtml = require("./embed/html.js");
} from "./utils/index.js";
import formatMarkdown from "./embed/markdown.js";
import formatCss from "./embed/css.js";
import formatGraphql from "./embed/graphql.js";
import formatHtml from "./embed/html.js";
function getLanguage(path) {
if (
@@ -302,4 +300,4 @@ function hasInvalidCookedValue({ quasis }) {
return quasis.some(({ value: { cooked } }) => cooked === null);
}
module.exports = embed;
export default embed;
+5 -5
View File
@@ -1,11 +1,11 @@
"use strict";
import { isNonEmptyArray } from "../../common/util.js";
import doc from "../../document/index.js";
import { printTemplateExpressions } from "../print/template-literal.js";
const { isNonEmptyArray } = require("../../common/util.js");
const {
builders: { indent, hardline, softline },
utils: { mapDoc, replaceEndOfLine, cleanDoc },
} = require("../../document/index.js");
const { printTemplateExpressions } = require("../print/template-literal.js");
} = doc;
function format(path, print, textToDoc) {
const node = path.getValue();
@@ -77,4 +77,4 @@ function replacePlaceholders(quasisDoc, expressionDocs) {
return expressionDocs.length === replaceCounter ? newDoc : null;
}
module.exports = format;
export default format;
+7 -7
View File
@@ -1,12 +1,12 @@
"use strict";
import doc from "../../document/index.js";
import {
escapeTemplateCharacters,
printTemplateExpressions,
} from "../print/template-literal.js";
const {
builders: { indent, join, hardline },
} = require("../../document/index.js");
const {
escapeTemplateCharacters,
printTemplateExpressions,
} = require("../print/template-literal.js");
} = doc;
function format(path, print, textToDoc) {
const node = path.getValue();
@@ -105,4 +105,4 @@ function printGraphqlComments(lines) {
return parts.length === 0 ? null : join(hardline, parts);
}
module.exports = format;
export default format;
+7 -7
View File
@@ -1,13 +1,13 @@
"use strict";
import doc from "../../document/index.js";
import {
printTemplateExpressions,
uncookTemplateElementValue,
} from "../print/template-literal.js";
const {
builders: { indent, line, hardline, group },
utils: { mapDoc },
} = require("../../document/index.js");
const {
printTemplateExpressions,
uncookTemplateElementValue,
} = require("../print/template-literal.js");
} = doc;
// The counter is needed to distinguish nested embeds.
let htmlTemplateLiteralCounter = 0;
@@ -97,4 +97,4 @@ function format(path, print, textToDoc, options, { parser }) {
]);
}
module.exports = format;
export default format;
+4 -4
View File
@@ -1,9 +1,9 @@
"use strict";
import doc from "../../document/index.js";
import { escapeTemplateCharacters } from "../print/template-literal.js";
const {
builders: { indent, softline, literalline, dedentToRoot },
} = require("../../document/index.js");
const { escapeTemplateCharacters } = require("../print/template-literal.js");
} = doc;
function format(path, print, textToDoc) {
const node = path.getValue();
@@ -37,4 +37,4 @@ function getIndentation(str) {
return firstMatchedIndent === null ? "" : firstMatchedIndent[1];
}
module.exports = format;
export default format;
+10 -7
View File
@@ -1,10 +1,11 @@
"use strict";
import { createRequire } from "module";
import createLanguage from "../utils/create-language.js";
import estreePrinter from "./printer-estree.js";
import estreeJsonPrinter from "./printer-estree-json.js";
import options from "./options.js";
import parsers from "./parse/parsers.js";
const createLanguage = require("../utils/create-language.js");
const estreePrinter = require("./printer-estree.js");
const estreeJsonPrinter = require("./printer-estree-json.js");
const options = require("./options.js");
const parsers = require("./parse/parsers.js");
const require = createRequire(import.meta.url);
const languages = [
createLanguage(
@@ -117,9 +118,11 @@ const printers = {
"estree-json": estreeJsonPrinter,
};
module.exports = {
const language = {
languages,
options,
printers,
parsers,
};
export default language;
+33
View File
@@ -0,0 +1,33 @@
// A cjs version of loc.js to use in `../main/parser.js`
"use strict";
const isNonEmptyArray = require("../utils/is-non-empty-array.js");
/**
* @typedef {import("./types/estree").Node} Node
*/
function locStart(node, opts) {
const { ignoreDecorators } = opts || {};
// Handle nodes with decorators. They should start at the first decorator
if (!ignoreDecorators) {
const decorators =
(node.declaration && node.declaration.decorators) || node.decorators;
if (isNonEmptyArray(decorators)) {
return locStart(decorators[0]);
}
}
return node.range ? node.range[0] : node.start;
}
function locEnd(node) {
return node.range ? node.range[1] : node.end;
}
module.exports = {
locStart,
locEnd,
};
+2 -9
View File
@@ -1,6 +1,4 @@
"use strict";
const isNonEmptyArray = require("../utils/is-non-empty-array.js");
import isNonEmptyArray from "../utils/is-non-empty-array.js";
/**
* @typedef {import("./types/estree").Node} Node
@@ -55,9 +53,4 @@ function hasSameLoc(nodeA, nodeB) {
return hasSameLocStart(nodeA, nodeB) && hasSameLocEnd(nodeA, nodeB);
}
module.exports = {
locStart,
locEnd,
hasSameLocStart,
hasSameLoc,
};
export { locStart, locEnd, hasSameLocStart, hasSameLoc };
+5 -7
View File
@@ -1,8 +1,6 @@
"use strict";
const getLast = require("../utils/get-last.js");
const isNonEmptyArray = require("../utils/is-non-empty-array.js");
const {
import getLast from "../utils/get-last.js";
import isNonEmptyArray from "../utils/is-non-empty-array.js";
import {
getFunctionParameters,
getLeftSidePathName,
hasFlowShorthandAnnotationComment,
@@ -15,7 +13,7 @@ const {
isCallExpression,
isMemberExpression,
isObjectProperty,
} = require("./utils/index.js");
} from "./utils/index.js";
function needsParens(path, options) {
const parent = path.getParentNode();
@@ -947,4 +945,4 @@ function shouldWrapFunctionForExportDefault(path, options) {
);
}
module.exports = needsParens;
export default needsParens;
+4 -4
View File
@@ -1,11 +1,9 @@
"use strict";
const commonOptions = require("../common/common-options.js");
import commonOptions from "../common/common-options.js";
const CATEGORY_JAVASCRIPT = "JavaScript";
// format based on https://github.com/prettier/prettier/blob/main/src/main/core-options.js
module.exports = {
const options = {
arrowParens: {
since: "1.9.0",
category: CATEGORY_JAVASCRIPT,
@@ -100,3 +98,5 @@ module.exports = {
},
singleAttributePerLine: commonOptions.singleAttributePerLine,
};
export default options;
-5
View File
@@ -1,5 +0,0 @@
{
"//TODO": "Remove this file when we close #10157",
"type": "commonjs",
"description": "A package.json file to use `.js` files in this directory as CommonJS module."
}
+5 -5
View File
@@ -1,11 +1,11 @@
"use strict";
import acorn from "./acorn.js";
import espree from "./espree.js";
const acorn = require("./acorn.js");
const espree = require("./espree.js");
module.exports = {
const parserAcornAndEspree = {
parsers: {
acorn,
espree,
},
};
export default parserAcornAndEspree;
+8 -8
View File
@@ -1,9 +1,11 @@
"use strict";
// TODO[@fisker]: try inline import these modules
import { Parser as AcornParser } from "acorn";
import acornJsx from "acorn-jsx";
const createError = require("../../common/parser-create-error.js");
const tryCombinations = require("../../utils/try-combinations.js");
const createParser = require("./utils/create-parser.js");
const postprocess = require("./postprocess/index.js");
import createError from "../../common/parser-create-error.js";
import tryCombinations from "../../utils/try-combinations.js";
import createParser from "./utils/create-parser.js";
import postprocess from "./postprocess/index.js";
/** @type {import("acorn").Options} */
const parseOptions = {
@@ -37,8 +39,6 @@ function createParseError(error) {
let parser;
const getParser = () => {
if (!parser) {
const { Parser: AcornParser } = require("acorn");
const acornJsx = require("acorn-jsx");
parser = AcornParser.extend(acornJsx());
}
return parser;
@@ -78,4 +78,4 @@ function parse(text, parsers, options = {}) {
return postprocess(ast, options);
}
module.exports = createParser(parse);
export default createParser(parse);
+6 -4
View File
@@ -1,10 +1,10 @@
"use strict";
// TODO[@fisker]: try inline import this module
import ngEstreeParser from "angular-estree-parser";
const { locStart, locEnd } = require("../loc.js");
import { locStart, locEnd } from "../loc.js";
function createParser(_parse) {
const parse = (text, parsers, options) => {
const ngEstreeParser = require("angular-estree-parser");
const node = _parse(text, ngEstreeParser);
return {
type: "NGRoot",
@@ -17,7 +17,7 @@ function createParser(_parse) {
return { astFormat: "estree", parse, locStart, locEnd };
}
module.exports = {
const parser = {
parsers: {
__ng_action: createParser((text, ng) => ng.parseAction(text)),
__ng_binding: createParser((text, ng) => ng.parseBinding(text)),
@@ -25,3 +25,5 @@ module.exports = {
__ng_directive: createParser((text, ng) => ng.parseTemplateBindings(text)),
},
};
export default parser;
+13 -10
View File
@@ -1,12 +1,13 @@
"use strict";
// TODO[@fisker]: try inline import this module
import babelParser from "@babel/parser";
const tryCombinations = require("../../utils/try-combinations.js");
const getShebang = require("../utils/get-shebang.js");
const getNextNonSpaceNonCommentCharacterIndexWithStartIndex = require("../../utils/text/get-next-non-space-non-comment-character-index-with-start-index.js");
const createParser = require("./utils/create-parser.js");
const createBabelParseError = require("./utils/create-babel-parse-error.js");
const postprocess = require("./postprocess/index.js");
const jsonParsers = require("./json.js");
import tryCombinations from "../../utils/try-combinations.js";
import getShebang from "../utils/get-shebang.js";
import getNextNonSpaceNonCommentCharacterIndexWithStartIndex from "../../utils/text/get-next-non-space-non-comment-character-index-with-start-index.js";
import createParser from "./utils/create-parser.js";
import createBabelParseError from "./utils/create-babel-parse-error.js";
import postprocess from "./postprocess/index.js";
import jsonParsers from "./json.js";
/**
* @typedef {import("@babel/parser").parse | import("@babel/parser").parseExpression} Parse
@@ -86,7 +87,7 @@ function isFlowFile(text, options) {
function parseWithOptions(parseMethod, text, options) {
// Inline the require to avoid loading all the JS if we don't use it
/** @type {Parse} */
const parse = require("@babel/parser")[parseMethod];
const parse = babelParser[parseMethod];
const ast = parse(text, options);
const error = ast.errors.find(
(error) => !allowedMessageCodes.has(error.reasonCode)
@@ -229,7 +230,7 @@ const babel = createParser(parse);
const babelExpression = createParser(parseExpression);
// Export as a plugin so we can reuse the same bundle for UMD loading
module.exports = {
const parser = {
parsers: {
babel,
"babel-flow": createParser(parseFlow),
@@ -245,3 +246,5 @@ module.exports = {
__babel_estree: createParser(parseEstree),
},
};
export default parser;
+10 -11
View File
@@ -1,10 +1,11 @@
"use strict";
// TODO[@fisker]: try inline import this module
import { parse as espreeParse } from "espree";
const createError = require("../../common/parser-create-error.js");
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");
import createError from "../../common/parser-create-error.js";
import tryCombinations from "../../utils/try-combinations.js";
import createParser from "./utils/create-parser.js";
import replaceHashbang from "./utils/replace-hashbang.js";
import postprocess from "./postprocess/index.js";
/** @type {import("espree").Options} */
const parseOptions = {
@@ -33,12 +34,10 @@ function createParseError(error) {
}
function parse(originalText, parsers, options = {}) {
const { parse } = require("espree");
const textToParse = replaceHashbang(originalText);
const { result: ast, error: moduleParseError } = tryCombinations(
() => parse(textToParse, { ...parseOptions, sourceType: "module" }),
() => parse(textToParse, { ...parseOptions, sourceType: "script" })
() => espreeParse(textToParse, { ...parseOptions, sourceType: "module" }),
() => espreeParse(textToParse, { ...parseOptions, sourceType: "script" })
);
if (!ast) {
@@ -50,4 +49,4 @@ function parse(originalText, parsers, options = {}) {
return postprocess(ast, options);
}
module.exports = createParser(parse);
export default createParser(parse);
+11 -9
View File
@@ -1,9 +1,11 @@
"use strict";
// TODO[@fisker]: try inline import this module
// Inline the require to avoid loading all the JS if we don't use it
import flow from "flow-parser";
const createError = require("../../common/parser-create-error.js");
const createParser = require("./utils/create-parser.js");
const replaceHashbang = require("./utils/replace-hashbang.js");
const postprocess = require("./postprocess/index.js");
import createError from "../../common/parser-create-error.js";
import createParser from "./utils/create-parser.js";
import replaceHashbang from "./utils/replace-hashbang.js";
import postprocess from "./postprocess/index.js";
// https://github.com/facebook/flow/tree/main/packages/flow-parser#options
// Keep this sync with `/scripts/sync-flow-test.js`
@@ -39,9 +41,7 @@ function createParseError(error) {
}
function parse(text, parsers, options = {}) {
// Inline the require to avoid loading all the JS if we don't use it
const { parse } = require("flow-parser");
const ast = parse(replaceHashbang(text), parseOptions);
const ast = flow.parse(replaceHashbang(text), parseOptions);
const [error] = ast.errors;
if (error) {
throw createParseError(error);
@@ -52,8 +52,10 @@ function parse(text, parsers, options = {}) {
}
// Export as a plugin so we can reuse the same bundle for UMD loading
module.exports = {
const parser = {
parsers: {
flow: createParser(parse),
},
};
export default parser;
+7 -7
View File
@@ -1,15 +1,15 @@
"use strict";
// TODO[@fisker]: try inline import this module
import { parseExpression } from "@babel/parser";
const isNonEmptyArray = require("../../utils/is-non-empty-array.js");
const createError = require("../../common/parser-create-error.js");
const createParser = require("./utils/create-parser.js");
const createBabelParseError = require("./utils/create-babel-parse-error.js");
import isNonEmptyArray from "../../utils/is-non-empty-array.js";
import createError from "../../common/parser-create-error.js";
import createParser from "./utils/create-parser.js";
import createBabelParseError from "./utils/create-babel-parse-error.js";
function createJsonParse(options = {}) {
const { allowComments = true } = options;
return function parse(text /*, parsers, options*/) {
const { parseExpression } = require("@babel/parser");
let ast;
try {
ast = parseExpression(text, {
@@ -145,4 +145,4 @@ const jsonParsers = {
}),
};
module.exports = jsonParsers;
export default jsonParsers;
+10 -8
View File
@@ -1,9 +1,10 @@
"use strict";
// TODO[@fisker]: try inline import this module
import { parse as meriyahParse } from "meriyah";
const createError = require("../../common/parser-create-error.js");
const tryCombinations = require("../../utils/try-combinations.js");
const createParser = require("./utils/create-parser.js");
const postprocess = require("./postprocess/index.js");
import createError from "../../common/parser-create-error.js";
import tryCombinations from "../../utils/try-combinations.js";
import createParser from "./utils/create-parser.js";
import postprocess from "./postprocess/index.js";
// https://github.com/meriyah/meriyah/blob/4676f60b6c149d7082bde2c9147f9ae2359c8075/src/parser.ts#L185
const parseOptions = {
@@ -42,12 +43,11 @@ const parseOptions = {
};
function parseWithOptions(text, module) {
const { parse } = require("meriyah");
const comments = [];
const tokens = [];
/** @type {any} */
const ast = parse(text, {
const ast = meriyahParse(text, {
...parseOptions,
module,
onComment: comments,
@@ -86,8 +86,10 @@ function parse(text, parsers, options = {}) {
return postprocess(ast, options);
}
module.exports = {
const parser = {
parsers: {
meriyah: createParser(parse),
},
};
export default parser;
+28 -21
View File
@@ -1,72 +1,79 @@
"use strict";
import babel from "./babel.js";
import flow from "./flow.js";
import typescript from "./typescript.js";
import angular from "./angular.js";
import acornAndEspree from "./acorn-and-espree.js";
import meriyah from "./meriyah.js";
module.exports = {
const parsers = {
// JS - Babel
get babel() {
return require("./babel.js").parsers.babel;
return babel.parsers.babel;
},
get "babel-flow"() {
return require("./babel.js").parsers["babel-flow"];
return babel.parsers["babel-flow"];
},
get "babel-ts"() {
return require("./babel.js").parsers["babel-ts"];
return babel.parsers["babel-ts"];
},
get json() {
return require("./babel.js").parsers.json;
return babel.parsers.json;
},
get json5() {
return require("./babel.js").parsers.json5;
return babel.parsers.json5;
},
get "json-stringify"() {
return require("./babel.js").parsers["json-stringify"];
return babel.parsers["json-stringify"];
},
get __js_expression() {
return require("./babel.js").parsers.__js_expression;
return babel.parsers.__js_expression;
},
get __vue_expression() {
return require("./babel.js").parsers.__vue_expression;
return babel.parsers.__vue_expression;
},
get __vue_event_binding() {
return require("./babel.js").parsers.__vue_event_binding;
return babel.parsers.__vue_event_binding;
},
// JS - Flow
get flow() {
return require("./flow.js").parsers.flow;
return flow.parsers.flow;
},
// JS - TypeScript
get typescript() {
return require("./typescript.js").parsers.typescript;
return typescript.parsers.typescript;
},
// JS - Angular Action
get __ng_action() {
return require("./angular.js").parsers.__ng_action;
return angular.parsers.__ng_action;
},
// JS - Angular Binding
get __ng_binding() {
return require("./angular.js").parsers.__ng_binding;
return angular.parsers.__ng_binding;
},
// JS - Angular Interpolation
get __ng_interpolation() {
return require("./angular.js").parsers.__ng_interpolation;
return angular.parsers.__ng_interpolation;
},
// JS - Angular Directive
get __ng_directive() {
return require("./angular.js").parsers.__ng_directive;
return angular.parsers.__ng_directive;
},
// JS - acorn
get acorn() {
return require("./acorn-and-espree.js").parsers.acorn;
return acornAndEspree.parsers.acorn;
},
// JS - espree
get espree() {
return require("./acorn-and-espree.js").parsers.espree;
return acornAndEspree.parsers.espree;
},
// JS - meriyah
get meriyah() {
return require("./meriyah.js").parsers.meriyah;
return meriyah.parsers.meriyah;
},
// JS - Babel Estree
get __babel_estree() {
return require("./babel.js").parsers.__babel_estree;
return babel.parsers.__babel_estree;
},
};
export default parsers;
+7 -9
View File
@@ -1,11 +1,9 @@
"use strict";
const { locStart, locEnd } = require("../../loc.js");
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");
import { locStart, locEnd } from "../../loc.js";
import isTsKeywordType from "../../utils/is-ts-keyword-type.js";
import isTypeCastComment from "../../utils/is-type-cast-comment.js";
import getLast from "../../../utils/get-last.js";
import visitNode from "./visit-node.js";
import { throwErrorForInvalidNodes } from "./typescript.js";
function postprocess(ast, options) {
if (
@@ -209,4 +207,4 @@ function rebalanceLogicalTree(node) {
});
}
module.exports = postprocess;
export default postprocess;
@@ -1,7 +1,5 @@
"use strict";
const createError = require("../../../common/parser-create-error.js");
const visitNode = require("./visit-node.js");
import createError from "../../../common/parser-create-error.js";
import visitNode from "./visit-node.js";
function throwSyntaxError(node, message) {
const { start, end } = node.loc;
@@ -78,4 +76,4 @@ function throwErrorForInvalidNodes(ast, options) {
});
}
module.exports = { throwErrorForInvalidNodes };
export { throwErrorForInvalidNodes };
@@ -1,5 +1,3 @@
"use strict";
function visitNode(node, fn) {
if (Array.isArray(node)) {
// As of Node.js 16 using raw for loop over Array.entries provides a
@@ -24,4 +22,4 @@ function visitNode(node, fn) {
return node;
}
module.exports = visitNode;
export default visitNode;
+10 -8
View File
@@ -1,10 +1,11 @@
"use strict";
// TODO[@fisker]: try inline import this module
import { parseWithNodeMaps } from "@typescript-eslint/typescript-estree";
const createError = require("../../common/parser-create-error.js");
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");
import createError from "../../common/parser-create-error.js";
import tryCombinations from "../../utils/try-combinations.js";
import createParser from "./utils/create-parser.js";
import replaceHashbang from "./utils/replace-hashbang.js";
import postprocess from "./postprocess/index.js";
/** @type {import("@typescript-eslint/typescript-estree").TSESTreeOptions} */
const parseOptions = {
@@ -36,7 +37,6 @@ function parse(text, parsers, options = {}) {
const textToParse = replaceHashbang(text);
const jsx = isProbablyJsx(text);
const { parseWithNodeMaps } = require("@typescript-eslint/typescript-estree");
const { result, error: firstError } = tryCombinations(
// Try passing with our best guess first.
() => parseWithNodeMaps(textToParse, { ...parseOptions, jsx }),
@@ -69,8 +69,10 @@ function isProbablyJsx(text) {
}
// Export as a plugin so we can reuse the same bundle for UMD loading
module.exports = {
const parser = {
parsers: {
typescript: createParser(parse),
},
};
export default parser;
@@ -1,6 +1,4 @@
"use strict";
const createError = require("../../../common/parser-create-error.js");
import createError from "../../../common/parser-create-error.js";
function createBabelParseError(error) {
// babel error prints (l:c) with cols that are zero indexed
@@ -15,4 +13,4 @@ function createBabelParseError(error) {
});
}
module.exports = createBabelParseError;
export default createBabelParseError;
+3 -5
View File
@@ -1,7 +1,5 @@
"use strict";
const { hasPragma } = require("../../pragma.js");
const { locStart, locEnd } = require("../../loc.js");
import { hasPragma } from "../../pragma.js";
import { locStart, locEnd } from "../../loc.js";
function createParser(options) {
options = typeof options === "function" ? { parse: options } : options;
@@ -15,4 +13,4 @@ function createParser(options) {
};
}
module.exports = createParser;
export default createParser;
@@ -1,5 +1,3 @@
"use strict";
// Replace `#!` with `//` so `typescript`, `flow`, and `espree` can parse it as line comment
// Inspired by ESLint parse function https://github.com/eslint/eslint/blob/9d6063add931f0803cae1676d5df307baf114360/lib/linter/linter.js#L635
function replaceHashbang(text) {
@@ -10,4 +8,4 @@ function replaceHashbang(text) {
return text;
}
module.exports = replaceHashbang;
export default replaceHashbang;
+4 -9
View File
@@ -1,8 +1,6 @@
"use strict";
const { parseWithComments, strip, extract, print } = require("jest-docblock");
const { normalizeEndOfLine } = require("../common/end-of-line.js");
const getShebang = require("./utils/get-shebang.js");
import { parseWithComments, strip, extract, print } from "jest-docblock";
import { normalizeEndOfLine } from "../common/end-of-line.js";
import getShebang from "./utils/get-shebang.js";
function parseDocBlock(text) {
const shebang = getShebang(text);
@@ -42,7 +40,4 @@ function insertPragma(originalText) {
);
}
module.exports = {
hasPragma,
insertPragma,
};
export { hasPragma, insertPragma };
+1 -3
View File
@@ -1,5 +1,3 @@
"use strict";
function preprocess(ast, options) {
switch (options.parser) {
case "json":
@@ -19,4 +17,4 @@ function preprocess(ast, options) {
}
}
module.exports = preprocess;
export default preprocess;
+5 -5
View File
@@ -1,10 +1,10 @@
"use strict";
import doc from "../../document/index.js";
import { hasNode, hasComment, getComments } from "../utils/index.js";
import { printBinaryishExpression } from "./binaryish.js";
const {
builders: { join, line, group },
} = require("../../document/index.js");
const { hasNode, hasComment, getComments } = require("../utils/index.js");
const { printBinaryishExpression } = require("./binaryish.js");
} = doc;
/** @typedef {import("../../common/ast-path")} AstPath */
@@ -125,4 +125,4 @@ function hasNgSideEffect(path) {
});
}
module.exports = { printAngular };
export { printAngular };
+12 -12
View File
@@ -1,21 +1,21 @@
"use strict";
const { printDanglingComments } = require("../../main/comments.js");
const {
builders: { line, softline, hardline, group, indent, ifBreak, fill },
} = require("../../document/index.js");
const { getLast, hasNewline } = require("../../common/util.js");
const {
import { printDanglingComments } from "../../main/comments.js";
import doc from "../../document/index.js";
import { getLast, hasNewline } from "../../common/util.js";
import {
shouldPrintComma,
hasComment,
CommentCheckFlags,
isNextLineEmpty,
isNumericLiteral,
isSignedNumericLiteral,
} = require("../utils/index.js");
const { locStart } = require("../loc.js");
} from "../utils/index.js";
import { locStart } from "../loc.js";
const { printOptionalToken, printTypeAnnotation } = require("./misc.js");
import { printOptionalToken, printTypeAnnotation } from "./misc.js";
const {
builders: { line, softline, hardline, group, indent, ifBreak, fill },
} = doc;
/** @typedef {import("../../document").Doc} Doc */
@@ -186,4 +186,4 @@ function printArrayItemsConcisely(path, options, print, trailingComma) {
return fill(parts);
}
module.exports = { printArray, printArrayItems, isConciselyPrintedArray };
export { printArray, printArrayItems, isConciselyPrintedArray };
+12 -12
View File
@@ -1,11 +1,6 @@
"use strict";
const { isNonEmptyArray, getStringWidth } = require("../../common/util.js");
const {
builders: { line, group, indent, indentIfBreak },
utils: { cleanDoc, willBreak, canBreak },
} = require("../../document/index.js");
const {
import { isNonEmptyArray, getStringWidth } from "../../common/util.js";
import doc from "../../document/index.js";
import {
hasLeadingOwnLineComment,
isBinaryish,
isStringLiteral,
@@ -18,9 +13,14 @@ const {
hasComment,
isSignedNumericLiteral,
isObjectProperty,
} = require("../utils/index.js");
const { shouldInlineLogicalExpression } = require("./binaryish.js");
const { printCallExpression } = require("./call-expression.js");
} from "../utils/index.js";
import { shouldInlineLogicalExpression } from "./binaryish.js";
import { printCallExpression } from "./call-expression.js";
const {
builders: { line, group, indent, indentIfBreak },
utils: { cleanDoc, willBreak, canBreak },
} = doc;
function printAssignment(
path,
@@ -462,7 +462,7 @@ function getTypeArgumentsFromCallExpression(node) {
);
}
module.exports = {
export {
printVariableDeclarator,
printAssignmentExpression,
printAssignment,
+17 -17
View File
@@ -1,7 +1,19 @@
"use strict";
import { printComments } from "../../main/comments.js";
import { getLast } from "../../common/util.js";
import doc from "../../document/index.js";
import {
hasLeadingOwnLineComment,
isBinaryish,
isJsxNode,
shouldFlatten,
hasComment,
CommentCheckFlags,
isCallExpression,
isMemberExpression,
isObjectProperty,
isEnabledHackPipeline,
} from "../utils/index.js";
const { printComments } = require("../../main/comments.js");
const { getLast } = require("../../common/util.js");
const {
builders: {
join,
@@ -14,19 +26,7 @@ const {
indentIfBreak,
},
utils: { cleanDoc, getDocParts, isConcat },
} = require("../../document/index.js");
const {
hasLeadingOwnLineComment,
isBinaryish,
isJsxNode,
shouldFlatten,
hasComment,
CommentCheckFlags,
isCallExpression,
isMemberExpression,
isObjectProperty,
isEnabledHackPipeline,
} = require("../utils/index.js");
} = doc;
/** @typedef {import("../../document").Doc} Doc */
@@ -337,4 +337,4 @@ function shouldInlineLogicalExpression(node) {
return false;
}
module.exports = { printBinaryishExpression, shouldInlineLogicalExpression };
export { printBinaryishExpression, shouldInlineLogicalExpression };
+12 -12
View File
@@ -1,18 +1,18 @@
"use strict";
const { printDanglingComments } = require("../../main/comments.js");
const { isNonEmptyArray } = require("../../common/util.js");
const {
builders: { hardline, indent },
} = require("../../document/index.js");
const {
import { printDanglingComments } from "../../main/comments.js";
import { isNonEmptyArray } from "../../common/util.js";
import doc from "../../document/index.js";
import {
hasComment,
CommentCheckFlags,
isNextLineEmpty,
} = require("../utils/index.js");
const { printHardlineAfterHeritage } = require("./class.js");
} from "../utils/index.js";
import { printHardlineAfterHeritage } from "./class.js";
const { printBody } = require("./statement.js");
import { printBody } from "./statement.js";
const {
builders: { hardline, indent },
} = doc;
/** @typedef {import("../../document").Doc} Doc */
@@ -107,4 +107,4 @@ function printBlockBody(path, options, print) {
return parts;
}
module.exports = { printBlock, printBlockBody };
export { printBlock, printBlockBody };
+11 -11
View File
@@ -1,8 +1,6 @@
"use strict";
const { printDanglingComments } = require("../../main/comments.js");
const { getLast, getPenultimate } = require("../../common/util.js");
const {
import { printDanglingComments } from "../../main/comments.js";
import { getLast, getPenultimate } from "../../common/util.js";
import {
getFunctionParameters,
hasComment,
CommentCheckFlags,
@@ -16,7 +14,12 @@ const {
isCallExpression,
isStringLiteral,
isObjectProperty,
} = require("../utils/index.js");
} from "../utils/index.js";
import doc from "../../document/index.js";
import { ArgExpansionBailout } from "../../common/errors.js";
import { isConciselyPrintedArray } from "./array.js";
const {
builders: {
@@ -30,10 +33,7 @@ const {
breakParent,
},
utils: { willBreak },
} = require("../../document/index.js");
const { ArgExpansionBailout } = require("../../common/errors.js");
const { isConciselyPrintedArray } = require("./array.js");
} = doc;
function printCallArguments(path, options, print) {
const node = path.getValue();
@@ -303,4 +303,4 @@ function isTypeModuleObjectExpression(node) {
);
}
module.exports = printCallArguments;
export default printCallArguments;
+11 -14
View File
@@ -1,10 +1,6 @@
"use strict";
const {
builders: { join, group },
} = require("../../document/index.js");
const pathNeedsParens = require("../needs-parens.js");
const {
import doc from "../../document/index.js";
import pathNeedsParens from "../needs-parens.js";
import {
getCallArguments,
hasFlowAnnotationComment,
isCallExpression,
@@ -13,13 +9,14 @@ const {
isTemplateOnItsOwnLine,
isTestCall,
iterateCallArgumentsPath,
} = require("../utils/index.js");
const printMemberChain = require("./member-chain.js");
const printCallArguments = require("./call-arguments.js");
} from "../utils/index.js";
import printMemberChain from "./member-chain.js";
import printCallArguments from "./call-arguments.js";
import { printOptionalToken, printFunctionTypeParameters } from "./misc.js";
const {
printOptionalToken,
printFunctionTypeParameters,
} = require("./misc.js");
builders: { join, group },
} = doc;
function printCallExpression(path, options, print) {
const node = path.getValue();
@@ -128,4 +125,4 @@ function isCommonsJsOrAmdCall(node, parentNode) {
return false;
}
module.exports = { printCallExpression };
export { printCallExpression };
+12 -18
View File
@@ -1,23 +1,17 @@
"use strict";
import { isNonEmptyArray, createGroupIdMapper } from "../../common/util.js";
import { printComments, printDanglingComments } from "../../main/comments.js";
import doc from "../../document/index.js";
import { hasComment, CommentCheckFlags } from "../utils/index.js";
import { getTypeParametersGroupId } from "./type-parameters.js";
import { printMethod } from "./function.js";
import { printOptionalToken, printTypeAnnotation } from "./misc.js";
import { printPropertyKey } from "./property.js";
import { printAssignment } from "./assignment.js";
import { printClassMemberDecorators } from "./decorators.js";
const {
isNonEmptyArray,
createGroupIdMapper,
} = require("../../common/util.js");
const {
printComments,
printDanglingComments,
} = require("../../main/comments.js");
const {
builders: { join, line, hardline, softline, group, indent, ifBreak },
} = require("../../document/index.js");
const { hasComment, CommentCheckFlags } = require("../utils/index.js");
const { getTypeParametersGroupId } = require("./type-parameters.js");
const { printMethod } = require("./function.js");
const { printOptionalToken, printTypeAnnotation } = require("./misc.js");
const { printPropertyKey } = require("./property.js");
const { printAssignment } = require("./assignment.js");
const { printClassMemberDecorators } = require("./decorators.js");
} = doc;
function printClass(path, options, print) {
const node = path.getValue();
@@ -226,7 +220,7 @@ function printClassProperty(path, options, print) {
return [printAssignment(path, options, print, parts, " =", "value"), semi];
}
module.exports = {
export {
printClass,
printClassMethod,
printClassProperty,
+8 -8
View File
@@ -1,14 +1,14 @@
"use strict";
import { hasNewline } from "../../common/util.js";
import doc from "../../document/index.js";
import { isLineComment } from "../utils/index.js";
import { locStart, locEnd } from "../loc.js";
import isBlockComment from "../utils/is-block-comment.js";
const { hasNewline } = require("../../common/util.js");
const {
builders: { join, hardline },
utils: { replaceTextEndOfLine },
} = require("../../document/index.js");
const { isLineComment } = require("../utils/index.js");
const { locStart, locEnd } = require("../loc.js");
const isBlockComment = require("../utils/is-block-comment.js");
} = doc;
function printComment(commentPath, options) {
const comment = commentPath.getValue();
@@ -77,4 +77,4 @@ function printIndentableBlockComment(comment) {
];
}
module.exports = { printComment };
export { printComment };
+6 -6
View File
@@ -1,11 +1,11 @@
"use strict";
import { isNonEmptyArray, hasNewline } from "../../common/util.js";
import doc from "../../document/index.js";
import { locStart, locEnd } from "../loc.js";
import { getParentExportDeclaration } from "../utils/index.js";
const { isNonEmptyArray, hasNewline } = require("../../common/util.js");
const {
builders: { line, hardline, join, breakParent, group },
} = require("../../document/index.js");
const { locStart, locEnd } = require("../loc.js");
const { getParentExportDeclaration } = require("../utils/index.js");
} = doc;
function printClassMemberDecorators(path, options, print) {
const node = path.getValue();
@@ -77,7 +77,7 @@ function hasDecoratorsBeforeExport(node) {
);
}
module.exports = {
export {
printDecorators,
printClassMemberDecorators,
printDecoratorsBeforeExport,
+23 -29
View File
@@ -1,23 +1,19 @@
"use strict";
/** @typedef {import("../../document").Doc} Doc */
const assert = require("assert");
const { printDanglingComments } = require("../../main/comments.js");
const { printString, printNumber } = require("../../common/util.js");
const {
builders: { hardline, softline, group, indent },
} = require("../../document/index.js");
const {
import assert from "assert";
import { printDanglingComments } from "../../main/comments.js";
import { printString, printNumber } from "../../common/util.js";
import doc from "../../document/index.js";
import {
getParentExportDeclaration,
isFunctionNotation,
isGetterOrSetter,
rawText,
shouldPrintComma,
} = require("../utils/index.js");
const { locStart, locEnd } = require("../loc.js");
const { printClass } = require("./class.js");
const {
} from "../utils/index.js";
import { locStart, locEnd } from "../loc.js";
import { printClass } from "./class.js";
import {
printOpaqueType,
printTypeAlias,
printIntersectionType,
@@ -25,24 +21,22 @@ const {
printFunctionType,
printTupleType,
printIndexedAccessType,
} = require("./type-annotation.js");
const { printInterface } = require("./interface.js");
const {
printTypeParameter,
printTypeParameters,
} = require("./type-parameters.js");
const {
printExportDeclaration,
printExportAllDeclaration,
} = require("./module.js");
const { printArrayItems } = require("./array.js");
const { printObject } = require("./object.js");
const { printPropertyKey } = require("./property.js");
const {
} from "./type-annotation.js";
import { printInterface } from "./interface.js";
import { printTypeParameter, printTypeParameters } from "./type-parameters.js";
import { printExportDeclaration, printExportAllDeclaration } from "./module.js";
import { printArrayItems } from "./array.js";
import { printObject } from "./object.js";
import { printPropertyKey } from "./property.js";
import {
printOptionalToken,
printTypeAnnotation,
printRestSpread,
} = require("./misc.js");
} from "./misc.js";
const {
builders: { hardline, softline, group, indent },
} = doc;
function printFlow(path, options, print) {
const node = path.getValue();
@@ -382,4 +376,4 @@ function printFlowDeclaration(path, printed) {
return ["declare ", printed];
}
module.exports = { printFlow };
export { printFlow };
+14 -14
View File
@@ -1,12 +1,7 @@
"use strict";
const { getNextNonSpaceNonCommentCharacter } = require("../../common/util.js");
const { printDanglingComments } = require("../../main/comments.js");
const {
builders: { line, hardline, softline, group, indent, ifBreak },
utils: { removeLines, willBreak },
} = require("../../document/index.js");
const {
import { getNextNonSpaceNonCommentCharacter } from "../../common/util.js";
import { printDanglingComments } from "../../main/comments.js";
import doc from "../../document/index.js";
import {
getFunctionParameters,
iterateFunctionParametersPath,
isSimpleType,
@@ -18,10 +13,15 @@ const {
shouldPrintComma,
hasComment,
isNextLineEmpty,
} = require("../utils/index.js");
const { locEnd } = require("../loc.js");
const { ArgExpansionBailout } = require("../../common/errors.js");
const { printFunctionTypeParameters } = require("./misc.js");
} from "../utils/index.js";
import { locEnd } from "../loc.js";
import { ArgExpansionBailout } from "../../common/errors.js";
import { printFunctionTypeParameters } from "./misc.js";
const {
builders: { line, hardline, softline, group, indent, ifBreak },
utils: { removeLines, willBreak },
} = doc;
function printFunctionParameters(
path,
@@ -223,7 +223,7 @@ function shouldGroupFunctionParameters(functionNode, returnTypeDoc) {
);
}
module.exports = {
export {
printFunctionParameters,
shouldHugFunctionParameters,
shouldGroupFunctionParameters,
+29 -31
View File
@@ -1,31 +1,15 @@
"use strict";
/** @typedef {import("../../document/doc-builders").Doc} Doc */
const assert = require("assert");
const {
import assert from "assert";
import {
printDanglingComments,
printCommentsSeparately,
} = require("../../main/comments.js");
const getLast = require("../../utils/get-last.js");
const {
getNextNonSpaceNonCommentCharacterIndex,
} = require("../../common/util.js");
const {
builders: {
line,
softline,
group,
indent,
ifBreak,
hardline,
join,
indentIfBreak,
},
utils: { removeLines, willBreak },
} = require("../../document/index.js");
const { ArgExpansionBailout } = require("../../common/errors.js");
const {
} from "../../main/comments.js";
import getLast from "../../utils/get-last.js";
import { getNextNonSpaceNonCommentCharacterIndex } from "../../common/util.js";
import doc from "../../document/index.js";
import { ArgExpansionBailout } from "../../common/errors.js";
import {
getFunctionParameters,
hasLeadingOwnLineComment,
isFlowAnnotationComment,
@@ -43,14 +27,28 @@ const {
getCallArguments,
hasNakedLeftSide,
getLeftSide,
} = require("../utils/index.js");
const { locEnd } = require("../loc.js");
const {
} from "../utils/index.js";
import { locEnd } from "../loc.js";
import {
printFunctionParameters,
shouldGroupFunctionParameters,
} = require("./function-parameters.js");
const { printPropertyKey } = require("./property.js");
const { printFunctionTypeParameters } = require("./misc.js");
} from "./function-parameters.js";
import { printPropertyKey } from "./property.js";
import { printFunctionTypeParameters } from "./misc.js";
const {
builders: {
line,
softline,
group,
indent,
ifBreak,
hardline,
join,
indentIfBreak,
},
utils: { removeLines, willBreak },
} = doc;
function printFunction(path, print, options, args) {
const node = path.getValue();
@@ -528,7 +526,7 @@ function returnArgumentHasLeadingComment(options, argument) {
return false;
}
module.exports = {
export {
printFunction,
printArrowFunction,
printMethod,
+3 -6
View File
@@ -1,8 +1,8 @@
"use strict";
import doc from "../../document/index.js";
const {
builders: { join, line, group, softline, indent },
} = require("../../document/index.js");
} = doc;
function printHtmlBinding(path, options, print) {
const node = path.getValue();
@@ -65,7 +65,4 @@ function isVueEventBindingExpression(node) {
}
}
module.exports = {
isVueEventBindingExpression,
printHtmlBinding,
};
export { isVueEventBindingExpression, printHtmlBinding };
+7 -11
View File
@@ -1,16 +1,12 @@
"use strict";
import { isNonEmptyArray } from "../../common/util.js";
import doc from "../../document/index.js";
import { hasComment, identity, CommentCheckFlags } from "../utils/index.js";
import { getTypeParametersGroupId } from "./type-parameters.js";
import { printTypeScriptModifiers } from "./misc.js";
const { isNonEmptyArray } = require("../../common/util.js");
const {
builders: { join, line, group, indent, ifBreak },
} = require("../../document/index.js");
const {
hasComment,
identity,
CommentCheckFlags,
} = require("../utils/index.js");
const { getTypeParametersGroupId } = require("./type-parameters.js");
const { printTypeScriptModifiers } = require("./misc.js");
} = doc;
function printInterface(path, options, print) {
const node = path.getValue();
@@ -74,4 +70,4 @@ function printInterface(path, options, print) {
return group(parts);
}
module.exports = { printInterface };
export { printInterface };
+19 -25
View File
@@ -1,9 +1,21 @@
"use strict";
import { printComments, printDanglingComments } from "../../main/comments.js";
import doc from "../../document/index.js";
import { getLast, getPreferredQuote } from "../../common/util.js";
import {
isJsxNode,
rawText,
isLiteral,
isCallExpression,
isStringLiteral,
isBinaryish,
hasComment,
CommentCheckFlags,
hasNodeIgnoreComment,
} from "../utils/index.js";
import pathNeedsParens from "../needs-parens.js";
import { willPrintOwnComments } from "../comments.js";
const {
printComments,
printDanglingComments,
} = require("../../main/comments.js");
const {
builders: {
line,
@@ -18,22 +30,7 @@ const {
join,
},
utils: { willBreak },
} = require("../../document/index.js");
const { getLast, getPreferredQuote } = require("../../common/util.js");
const {
isJsxNode,
rawText,
isLiteral,
isCallExpression,
isStringLiteral,
isBinaryish,
hasComment,
CommentCheckFlags,
hasNodeIgnoreComment,
} = require("../utils/index.js");
const pathNeedsParens = require("../needs-parens.js");
const { willPrintOwnComments } = require("../comments.js");
} = doc;
const isEmptyStringOrAnyLine = (doc) =>
doc === "" || doc === line || doc === hardline || doc === softline;
@@ -849,7 +846,4 @@ function hasJsxIgnoreComment(path) {
);
}
module.exports = {
hasJsxIgnoreComment,
printJsx,
};
export { hasJsxIgnoreComment, printJsx };
+2 -5
View File
@@ -1,5 +1,4 @@
"use strict";
const { printString, printNumber } = require("../../common/util.js");
import { printString, printNumber } from "../../common/util.js";
function printLiteral(path, options /*, print*/) {
const node = path.getNode();
@@ -57,6 +56,4 @@ function printRegex({ pattern, flags }) {
return `/${pattern}/${flags}`;
}
module.exports = {
printLiteral,
};
export { printLiteral };
+18 -18
View File
@@ -1,13 +1,11 @@
"use strict";
const { printComments } = require("../../main/comments.js");
const {
import { printComments } from "../../main/comments.js";
import {
getLast,
isNextLineEmptyAfterIndex,
getNextNonSpaceNonCommentCharacterIndex,
} = require("../../common/util.js");
const pathNeedsParens = require("../needs-parens.js");
const {
} from "../../common/util.js";
import pathNeedsParens from "../needs-parens.js";
import {
isCallExpression,
isMemberExpression,
isFunctionOrArrowExpression,
@@ -18,8 +16,17 @@ const {
hasComment,
CommentCheckFlags,
isNextLineEmpty,
} = require("../utils/index.js");
const { locEnd } = require("../loc.js");
} from "../utils/index.js";
import { locEnd } from "../loc.js";
import doc from "../../document/index.js";
import printCallArguments from "./call-arguments.js";
import { printMemberLookup } from "./member.js";
import {
printOptionalToken,
printFunctionTypeParameters,
printBindExpressionCallee,
} from "./misc.js";
const {
builders: {
@@ -32,14 +39,7 @@ const {
label,
},
utils: { willBreak },
} = require("../../document/index.js");
const printCallArguments = require("./call-arguments.js");
const { printMemberLookup } = require("./member.js");
const {
printOptionalToken,
printFunctionTypeParameters,
printBindExpressionCallee,
} = require("./misc.js");
} = doc;
// We detect calls on member expressions specially to format a
// common pattern better. The pattern we are looking for is this:
@@ -407,4 +407,4 @@ function printMemberChain(path, options, print) {
return label("member-chain", result);
}
module.exports = printMemberChain;
export default printMemberChain;
+9 -9
View File
@@ -1,14 +1,14 @@
"use strict";
const {
builders: { softline, group, indent, label },
} = require("../../document/index.js");
const {
import doc from "../../document/index.js";
import {
isNumericLiteral,
isMemberExpression,
isCallExpression,
} = require("../utils/index.js");
const { printOptionalToken } = require("./misc.js");
} from "../utils/index.js";
import { printOptionalToken } from "./misc.js";
const {
builders: { softline, group, indent, label },
} = doc;
function printMemberExpression(path, options, print) {
const node = path.getValue();
@@ -68,4 +68,4 @@ function printMemberLookup(path, options, print) {
return group([optional, "[", indent([softline, property]), softline, "]"]);
}
module.exports = { printMemberExpression, printMemberLookup };
export { printMemberExpression, printMemberLookup };
+5 -5
View File
@@ -1,10 +1,10 @@
"use strict";
import { isNonEmptyArray } from "../../common/util.js";
import doc from "../../document/index.js";
import { isFlowAnnotationComment } from "../utils/index.js";
const { isNonEmptyArray } = require("../../common/util.js");
const {
builders: { indent, join, line },
} = require("../../document/index.js");
const { isFlowAnnotationComment } = require("../utils/index.js");
} = doc;
function printOptionalToken(path) {
const node = path.getValue();
@@ -90,7 +90,7 @@ function printRestSpread(path, options, print) {
return ["...", print("argument"), printTypeAnnotation(path, options, print)];
}
module.exports = {
export {
printOptionalToken,
printFunctionTypeParameters,
printBindExpressionCallee,
+13 -13
View File
@@ -1,24 +1,24 @@
"use strict";
import { isNonEmptyArray } from "../../common/util.js";
import doc from "../../document/index.js";
import { printDanglingComments } from "../../main/comments.js";
const { isNonEmptyArray } = require("../../common/util.js");
const {
builders: { softline, group, indent, join, line, ifBreak, hardline },
} = require("../../document/index.js");
const { printDanglingComments } = require("../../main/comments.js");
const {
import {
hasComment,
CommentCheckFlags,
shouldPrintComma,
needsHardlineAfterDanglingComment,
isStringLiteral,
rawText,
} = require("../utils/index.js");
const { locStart, hasSameLoc } = require("../loc.js");
const {
} from "../utils/index.js";
import { locStart, hasSameLoc } from "../loc.js";
import {
hasDecoratorsBeforeExport,
printDecoratorsBeforeExport,
} = require("./decorators.js");
} from "./decorators.js";
const {
builders: { softline, group, indent, join, line, ifBreak, hardline },
} = doc;
/**
* @typedef {import("../../document").Doc} Doc
@@ -354,7 +354,7 @@ function isShorthandSpecifier(specifier) {
}
}
module.exports = {
export {
printImportDeclaration,
printExportDeclaration,
printExportAllDeclaration,
+16 -16
View File
@@ -1,28 +1,28 @@
"use strict";
const { printDanglingComments } = require("../../main/comments.js");
const {
builders: { line, softline, group, indent, ifBreak, hardline },
} = require("../../document/index.js");
const {
import { printDanglingComments } from "../../main/comments.js";
import doc from "../../document/index.js";
import {
getLast,
hasNewlineInRange,
hasNewline,
isNonEmptyArray,
} = require("../../common/util.js");
const {
} from "../../common/util.js";
import {
shouldPrintComma,
hasComment,
getComments,
CommentCheckFlags,
isNextLineEmpty,
} = require("../utils/index.js");
const { locStart, locEnd } = require("../loc.js");
} from "../utils/index.js";
import { locStart, locEnd } from "../loc.js";
const { printOptionalToken, printTypeAnnotation } = require("./misc.js");
const { shouldHugFunctionParameters } = require("./function-parameters.js");
const { shouldHugType } = require("./type-annotation.js");
const { printHardlineAfterHeritage } = require("./class.js");
import { printOptionalToken, printTypeAnnotation } from "./misc.js";
import { shouldHugFunctionParameters } from "./function-parameters.js";
import { shouldHugType } from "./type-annotation.js";
import { printHardlineAfterHeritage } from "./class.js";
const {
builders: { line, softline, group, indent, ifBreak, hardline },
} = doc;
/** @typedef {import("../../document").Doc} Doc */
@@ -243,4 +243,4 @@ function printObject(path, options, print) {
return group(content, { shouldBreak });
}
module.exports = { printObject };
export { printObject };
+6 -8
View File
@@ -1,15 +1,13 @@
"use strict";
const { printComments } = require("../../main/comments.js");
const { printString, printNumber } = require("../../common/util.js");
const {
import { printComments } from "../../main/comments.js";
import { printString, printNumber } from "../../common/util.js";
import {
isNumericLiteral,
isSimpleNumber,
isStringLiteral,
isStringPropSafeToUnquote,
rawText,
} = require("../utils/index.js");
const { printAssignment } = require("./assignment.js");
} from "../utils/index.js";
import { printAssignment } from "./assignment.js";
const needsQuoteProps = new WeakMap();
@@ -105,4 +103,4 @@ function printProperty(path, options, print) {
);
}
module.exports = { printProperty, printPropertyKey };
export { printProperty, printPropertyKey };
+10 -13
View File
@@ -1,10 +1,6 @@
"use strict";
const {
builders: { hardline },
} = require("../../document/index.js");
const pathNeedsParens = require("../needs-parens.js");
const {
import doc from "../../document/index.js";
import pathNeedsParens from "../needs-parens.js";
import {
getLeftSidePathName,
hasNakedLeftSide,
isJsxNode,
@@ -12,8 +8,12 @@ const {
hasComment,
CommentCheckFlags,
isNextLineEmpty,
} = require("../utils/index.js");
const { shouldPrintParamsWithoutParens } = require("./function.js");
} from "../utils/index.js";
import { shouldPrintParamsWithoutParens } from "./function.js";
const {
builders: { hardline },
} = doc;
/**
* @typedef {import("../../document").Doc} Doc
@@ -245,7 +245,4 @@ function shouldPrintSemicolonAfterClassProperty(node, nextNode) {
return false;
}
module.exports = {
printBody,
printSwitchCaseConsequent,
};
export { printBody, printSwitchCaseConsequent };
+12 -12
View File
@@ -1,7 +1,14 @@
"use strict";
import getLast from "../../utils/get-last.js";
import { getStringWidth, getIndentSize } from "../../common/util.js";
import doc from "../../document/index.js";
import {
isBinaryish,
isJestEachTemplateLiteral,
isSimpleTemplateLiteral,
hasComment,
isMemberExpression,
} from "../utils/index.js";
const getLast = require("../../utils/get-last.js");
const { getStringWidth, getIndentSize } = require("../../common/util.js");
const {
builders: {
join,
@@ -15,14 +22,7 @@ const {
},
printer: { printDocToString },
utils: { mapDoc },
} = require("../../document/index.js");
const {
isBinaryish,
isJestEachTemplateLiteral,
isSimpleTemplateLiteral,
hasComment,
isMemberExpression,
} = require("../utils/index.js");
} = doc;
function printTemplateLiteral(path, print, options) {
const node = path.getValue();
@@ -232,7 +232,7 @@ function uncookTemplateElementValue(cookedValue) {
return cookedValue.replace(/([\\`]|\${)/g, "\\$1");
}
module.exports = {
export {
printTemplateLiteral,
printTemplateExpressions,
escapeTemplateCharacters,
+9 -9
View File
@@ -1,14 +1,14 @@
"use strict";
const { hasNewlineInRange } = require("../../common/util.js");
const {
import { hasNewlineInRange } from "../../common/util.js";
import {
isJsxNode,
getComments,
isCallExpression,
isMemberExpression,
} = require("../utils/index.js");
const { locStart, locEnd } = require("../loc.js");
const isBlockComment = require("../utils/is-block-comment.js");
} from "../utils/index.js";
import { locStart, locEnd } from "../loc.js";
import isBlockComment from "../utils/is-block-comment.js";
import doc from "../../document/index.js";
const {
builders: {
line,
@@ -20,7 +20,7 @@ const {
dedent,
breakParent,
},
} = require("../../document/index.js");
} = doc;
/**
* @typedef {import("../../document").Doc} Doc
@@ -352,4 +352,4 @@ function printTernary(path, options, print) {
: result;
}
module.exports = { printTernary };
export { printTernary };
+16 -19
View File
@@ -1,28 +1,25 @@
"use strict";
const {
printComments,
printDanglingComments,
} = require("../../main/comments.js");
const { getLast, isNonEmptyArray } = require("../../common/util.js");
const {
builders: { group, join, line, softline, indent, align, ifBreak },
} = require("../../document/index.js");
const pathNeedsParens = require("../needs-parens.js");
const { locStart } = require("../loc.js");
const {
import { printComments, printDanglingComments } from "../../main/comments.js";
import { getLast, isNonEmptyArray } from "../../common/util.js";
import doc from "../../document/index.js";
import pathNeedsParens from "../needs-parens.js";
import { locStart } from "../loc.js";
import {
isSimpleType,
isObjectType,
hasLeadingOwnLineComment,
isObjectTypePropertyAFunction,
shouldPrintComma,
} = require("../utils/index.js");
const { printAssignment } = require("./assignment.js");
const {
} from "../utils/index.js";
import { printAssignment } from "./assignment.js";
import {
printFunctionParameters,
shouldGroupFunctionParameters,
} = require("./function-parameters.js");
const { printArrayItems } = require("./array.js");
} from "./function-parameters.js";
import { printArrayItems } from "./array.js";
const {
builders: { group, join, line, softline, indent, align, ifBreak },
} = doc;
function shouldHugType(node) {
if (isSimpleType(node) || isObjectType(node)) {
@@ -314,7 +311,7 @@ function printIndexedAccessType(path, options, print) {
return [print("objectType"), leftDelimiter, print("indexType"), "]"];
}
module.exports = {
export {
printOpaqueType,
printTypeAlias,
printIntersectionType,
+12 -16
View File
@@ -1,10 +1,6 @@
"use strict";
const { printDanglingComments } = require("../../main/comments.js");
const {
builders: { join, line, hardline, softline, group, indent, ifBreak },
} = require("../../document/index.js");
const {
import { printDanglingComments } from "../../main/comments.js";
import doc from "../../document/index.js";
import {
isTestCall,
hasComment,
CommentCheckFlags,
@@ -12,10 +8,14 @@ const {
shouldPrintComma,
getFunctionParameters,
isObjectType,
} = require("../utils/index.js");
const { createGroupIdMapper } = require("../../common/util.js");
const { shouldHugType } = require("./type-annotation.js");
const { isArrowFunctionVariableDeclarator } = require("./assignment.js");
} from "../utils/index.js";
import { createGroupIdMapper } from "../../common/util.js";
import { shouldHugType } from "./type-annotation.js";
import { isArrowFunctionVariableDeclarator } from "./assignment.js";
const {
builders: { join, line, hardline, softline, group, indent, ifBreak },
} = doc;
const getTypeParametersGroupId = createGroupIdMapper("typeParameters");
@@ -144,8 +144,4 @@ function printTypeParameter(path, options, print) {
return parts;
}
module.exports = {
printTypeParameter,
printTypeParameters,
getTypeParametersGroupId,
};
export { printTypeParameter, printTypeParameters, getTypeParametersGroupId };
+38 -41
View File
@@ -1,7 +1,40 @@
"use strict";
import { printDanglingComments } from "../../main/comments.js";
import { hasNewlineInRange } from "../../common/util.js";
import doc from "../../document/index.js";
import {
isLiteral,
getTypeScriptMappedTypeModifier,
shouldPrintComma,
isCallExpression,
isMemberExpression,
} from "../utils/index.js";
import isTsKeywordType from "../utils/is-ts-keyword-type.js";
import { locStart, locEnd } from "../loc.js";
import { printOptionalToken, printTypeScriptModifiers } from "./misc.js";
import { printTernary } from "./ternary.js";
import {
printFunctionParameters,
shouldGroupFunctionParameters,
} from "./function-parameters.js";
import { printTemplateLiteral } from "./template-literal.js";
import { printArrayItems } from "./array.js";
import { printObject } from "./object.js";
import { printClassProperty, printClassMethod } from "./class.js";
import { printTypeParameter, printTypeParameters } from "./type-parameters.js";
import { printPropertyKey } from "./property.js";
import { printFunction, printMethodInternal } from "./function.js";
import { printInterface } from "./interface.js";
import { printBlock } from "./block.js";
import {
printTypeAlias,
printIntersectionType,
printUnionType,
printFunctionType,
printTupleType,
printIndexedAccessType,
} from "./type-annotation.js";
const { printDanglingComments } = require("../../main/comments.js");
const { hasNewlineInRange } = require("../../common/util.js");
const {
builders: {
join,
@@ -13,43 +46,7 @@ const {
conditionalGroup,
ifBreak,
},
} = require("../../document/index.js");
const {
isLiteral,
getTypeScriptMappedTypeModifier,
shouldPrintComma,
isCallExpression,
isMemberExpression,
} = require("../utils/index.js");
const isTsKeywordType = require("../utils/is-ts-keyword-type.js");
const { locStart, locEnd } = require("../loc.js");
const { printOptionalToken, printTypeScriptModifiers } = require("./misc.js");
const { printTernary } = require("./ternary.js");
const {
printFunctionParameters,
shouldGroupFunctionParameters,
} = require("./function-parameters.js");
const { printTemplateLiteral } = require("./template-literal.js");
const { printArrayItems } = require("./array.js");
const { printObject } = require("./object.js");
const { printClassProperty, printClassMethod } = require("./class.js");
const {
printTypeParameter,
printTypeParameters,
} = require("./type-parameters.js");
const { printPropertyKey } = require("./property.js");
const { printFunction, printMethodInternal } = require("./function.js");
const { printInterface } = require("./interface.js");
const { printBlock } = require("./block.js");
const {
printTypeAlias,
printIntersectionType,
printUnionType,
printFunctionType,
printTupleType,
printIndexedAccessType,
} = require("./type-annotation.js");
} = doc;
function printTypescript(path, options, print) {
const node = path.getValue();
@@ -528,4 +525,4 @@ function printTypescript(path, options, print) {
}
}
module.exports = { printTypescript };
export { printTypescript };
+6 -4
View File
@@ -1,9 +1,9 @@
"use strict";
import doc from "../document/index.js";
import preprocess from "./print-preprocess.js";
const {
builders: { hardline, indent, join },
} = require("../document/index.js");
const preprocess = require("./print-preprocess.js");
} = doc;
function genericPrint(path, options, print) {
const node = path.getValue();
@@ -109,8 +109,10 @@ function clean(node, newNode /*, parent*/) {
clean.ignoredProperties = ignoredProperties;
module.exports = {
const printer = {
preprocess,
print: genericPrint,
massageAstNode: clean,
};
export default printer;
+50 -48
View File
@@ -1,21 +1,16 @@
"use strict";
/** @typedef {import("../document").Doc} Doc */
// TODO(azz): anything that imports from main shouldn't be in a `language-*` dir.
const { printDanglingComments } = require("../main/comments.js");
const { hasNewline } = require("../common/util.js");
const {
builders: { join, line, hardline, softline, group, indent },
utils: { replaceTextEndOfLine },
} = require("../document/index.js");
const embed = require("./embed.js");
const clean = require("./clean.js");
const { insertPragma } = require("./pragma.js");
const handleComments = require("./comments.js");
const pathNeedsParens = require("./needs-parens.js");
const preprocess = require("./print-preprocess.js");
const {
import { printDanglingComments } from "../main/comments.js";
import { hasNewline } from "../common/util.js";
import doc from "../document/index.js";
import embed from "./embed.js";
import clean from "./clean.js";
import { insertPragma } from "./pragma.js";
import * as handleComments from "./comments.js";
import pathNeedsParens from "./needs-parens.js";
import preprocess from "./print-preprocess.js";
import {
hasFlowShorthandAnnotationComment,
hasComment,
CommentCheckFlags,
@@ -28,60 +23,65 @@ const {
isCallExpression,
isMemberExpression,
markerForIfWithoutBlockAndSameLineComment,
} = require("./utils/index.js");
const { locStart, locEnd } = require("./loc.js");
const isBlockComment = require("./utils/is-block-comment.js");
} from "./utils/index.js";
import { locStart, locEnd } from "./loc.js";
import isBlockComment from "./utils/is-block-comment.js";
const {
import {
printHtmlBinding,
isVueEventBindingExpression,
} = require("./print/html-binding.js");
const { printAngular } = require("./print/angular.js");
const { printJsx, hasJsxIgnoreComment } = require("./print/jsx.js");
const { printFlow } = require("./print/flow.js");
const { printTypescript } = require("./print/typescript.js");
const {
} from "./print/html-binding.js";
import { printAngular } from "./print/angular.js";
import { printJsx, hasJsxIgnoreComment } from "./print/jsx.js";
import { printFlow } from "./print/flow.js";
import { printTypescript } from "./print/typescript.js";
import {
printOptionalToken,
printBindExpressionCallee,
printTypeAnnotation,
adjustClause,
printRestSpread,
} = require("./print/misc.js");
const {
} from "./print/misc.js";
import {
printImportDeclaration,
printExportDeclaration,
printExportAllDeclaration,
printModuleSpecifier,
} = require("./print/module.js");
const { printTernary } = require("./print/ternary.js");
const { printTemplateLiteral } = require("./print/template-literal.js");
const { printArray } = require("./print/array.js");
const { printObject } = require("./print/object.js");
const {
} from "./print/module.js";
import { printTernary } from "./print/ternary.js";
import { printTemplateLiteral } from "./print/template-literal.js";
import { printArray } from "./print/array.js";
import { printObject } from "./print/object.js";
import {
printClass,
printClassMethod,
printClassProperty,
} = require("./print/class.js");
const { printProperty } = require("./print/property.js");
const {
} from "./print/class.js";
import { printProperty } from "./print/property.js";
import {
printFunction,
printArrowFunction,
printMethod,
printReturnStatement,
printThrowStatement,
} = require("./print/function.js");
const { printCallExpression } = require("./print/call-expression.js");
const {
} from "./print/function.js";
import { printCallExpression } from "./print/call-expression.js";
import {
printVariableDeclarator,
printAssignmentExpression,
} = require("./print/assignment.js");
const { printBinaryishExpression } = require("./print/binaryish.js");
const { printSwitchCaseConsequent } = require("./print/statement.js");
const { printMemberExpression } = require("./print/member.js");
const { printBlock, printBlockBody } = require("./print/block.js");
const { printComment } = require("./print/comment.js");
const { printLiteral } = require("./print/literal.js");
const { printDecorators } = require("./print/decorators.js");
} from "./print/assignment.js";
import { printBinaryishExpression } from "./print/binaryish.js";
import { printSwitchCaseConsequent } from "./print/statement.js";
import { printMemberExpression } from "./print/member.js";
import { printBlock, printBlockBody } from "./print/block.js";
import { printComment } from "./print/comment.js";
import { printLiteral } from "./print/literal.js";
import { printDecorators } from "./print/decorators.js";
const {
builders: { join, line, hardline, softline, group, indent },
utils: { replaceTextEndOfLine },
} = doc;
function genericPrint(path, options, print, args) {
const printed = printPathNoParens(path, options, print, args);
@@ -835,7 +835,7 @@ function canAttachComment(node) {
);
}
module.exports = {
const printer = {
preprocess,
print: genericPrint,
embed,
@@ -857,3 +857,5 @@ module.exports = {
},
getCommentChildNodes: handleComments.getCommentChildNodes,
};
export default printer;
+1 -3
View File
@@ -1,5 +1,3 @@
"use strict";
function getShebang(text) {
if (!text.startsWith("#!")) {
return "";
@@ -11,4 +9,4 @@ function getShebang(text) {
return text.slice(0, index);
}
module.exports = getShebang;
export default getShebang;
+8 -8
View File
@@ -1,16 +1,16 @@
"use strict";
const isIdentifierName = require("esutils").keyword.isIdentifierNameES5;
const {
import esutils from "esutils";
import {
getLast,
hasNewline,
skipWhitespace,
isNonEmptyArray,
isNextLineEmptyAfterIndex,
getStringWidth,
} = require("../../common/util.js");
const { locStart, locEnd, hasSameLocStart } = require("../loc.js");
const isBlockComment = require("./is-block-comment.js");
} from "../../common/util.js";
import { locStart, locEnd, hasSameLocStart } from "../loc.js";
import isBlockComment from "./is-block-comment.js";
const isIdentifierName = esutils.keyword.isIdentifierNameES5;
/**
* @typedef {import("../types/estree").Node} Node
@@ -1311,7 +1311,7 @@ const markerForIfWithoutBlockAndSameLineComment = Symbol(
"ifWithoutBlockAndSameLineComment"
);
module.exports = {
export {
getFunctionParameters,
iterateFunctionParametersPath,
getCallArguments,
+1 -3
View File
@@ -1,5 +1,3 @@
"use strict";
/**
* @typedef {import("../types/estree").Comment} Comment
*/
@@ -17,4 +15,4 @@ function isBlockComment(comment) {
);
}
module.exports = isBlockComment;
export default isBlockComment;
+1 -2
View File
@@ -1,4 +1,3 @@
"use strict";
/**
* @returns {boolean}
*/
@@ -6,4 +5,4 @@ function isTsKeywordType({ type }) {
return type.startsWith("TS") && type.endsWith("Keyword");
}
module.exports = isTsKeywordType;
export default isTsKeywordType;
@@ -1,6 +1,4 @@
"use strict";
const isBlockComment = require("./is-block-comment.js");
import isBlockComment from "./is-block-comment.js";
/**
* @typedef {import("../types/estree").Comment} Comment
@@ -21,4 +19,4 @@ function isTypeCastComment(comment) {
);
}
module.exports = isTypeCastComment;
export default isTypeCastComment;
+2 -1
View File
@@ -1,4 +1,5 @@
import { createRequire } from "module";
import js from "./language-js/index.js";
import css from "./language-css/index.js";
import handlebars from "./language-handlebars/index.js";
import graphql from "./language-graphql/index.js";
@@ -10,7 +11,7 @@ const require = createRequire(import.meta.url);
// We need to list the parsers and getters so we can load them only when necessary.
const languages = [
// JS
require("./language-js/index.js"),
js,
// CSS
css,
// Handlebars
+2 -1
View File
@@ -2,7 +2,8 @@
const path = require("path");
const { ConfigError } = require("../common/errors.js");
const jsLoc = require("../language-js/loc.js");
// TODO: Use esm version
const jsLoc = require("../language-js/loc.cjs");
const { locStart, locEnd } = jsLoc;