diff --git a/src/language-js/comments/attach/handle-for-x-statement-comments.js b/src/language-js/comments/attach/handle-for-x-statement-comments.js index 5feddb8f2..204a4a968 100644 --- a/src/language-js/comments/attach/handle-for-x-statement-comments.js +++ b/src/language-js/comments/attach/handle-for-x-statement-comments.js @@ -1,5 +1,5 @@ import { addLeadingComment } from "../../../main/comments/utilities.js"; -import { locStart } from "../../loc.js"; +import { locStart } from "../../location/index.js"; import { stripComments } from "../../utilities/strip-comments.js"; function handleForXStatementComments({ diff --git a/src/language-js/comments/attach/handle-if-statement-comments.js b/src/language-js/comments/attach/handle-if-statement-comments.js index 1f62e38ec..74379b456 100644 --- a/src/language-js/comments/attach/handle-if-statement-comments.js +++ b/src/language-js/comments/attach/handle-if-statement-comments.js @@ -5,7 +5,7 @@ import { } from "../../../main/comments/utilities.js"; import getNextNonSpaceNonCommentCharacter from "../../../utilities/get-next-non-space-non-comment-character.js"; import hasNewlineInRange from "../../../utilities/has-newline-in-range.js"; -import { locEnd, locStart } from "../../loc.js"; +import { locEnd, locStart } from "../../location/index.js"; import { stripComments } from "../../utilities/strip-comments.js"; import { isSingleLineComment } from "./utilities.js"; diff --git a/src/language-js/comments/attach/handle-while-like-comments.js b/src/language-js/comments/attach/handle-while-like-comments.js index 888005119..21f4bd761 100644 --- a/src/language-js/comments/attach/handle-while-like-comments.js +++ b/src/language-js/comments/attach/handle-while-like-comments.js @@ -3,7 +3,7 @@ import { addTrailingComment, } from "../../../main/comments/utilities.js"; import getNextNonSpaceNonCommentCharacter from "../../../utilities/get-next-non-space-non-comment-character.js"; -import { locEnd } from "../../loc.js"; +import { locEnd } from "../../location/index.js"; /** @import {CommentContext} from "../handle-comments.js" diff --git a/src/language-js/comments/attach/utilities.js b/src/language-js/comments/attach/utilities.js index cac2f7e08..826520f6c 100644 --- a/src/language-js/comments/attach/utilities.js +++ b/src/language-js/comments/attach/utilities.js @@ -3,7 +3,7 @@ import { addLeadingComment, } from "../../../main/comments/utilities.js"; import hasNewlineInRange from "../../../utilities/has-newline-in-range.js"; -import { locEnd, locStart } from "../../loc.js"; +import { locEnd, locStart } from "../../location/index.js"; import { isLineComment } from "../../utilities/comment-types.js"; /** diff --git a/src/language-js/comments/handle-comments.js b/src/language-js/comments/handle-comments.js index c71d8c7a6..f7d72802d 100644 --- a/src/language-js/comments/handle-comments.js +++ b/src/language-js/comments/handle-comments.js @@ -8,7 +8,7 @@ import getNextNonSpaceNonCommentCharacterIndex from "../../utilities/get-next-no import hasNewline from "../../utilities/has-newline.js"; import hasNewlineInRange from "../../utilities/has-newline-in-range.js"; import isNonEmptyArray from "../../utilities/is-non-empty-array.js"; -import { locEnd, locStart } from "../loc.js"; +import { locEnd, locStart } from "../location/index.js"; import { getCallArguments } from "../utilities/call-arguments.js"; import { isInsideCallOrNewExpressionParentheses } from "../utilities/call-or-new-expression-parentheses.js"; import { isBlockComment, isLineComment } from "../utilities/comment-types.js"; diff --git a/src/language-js/loc.js b/src/language-js/loc.js deleted file mode 100644 index fa956c140..000000000 --- a/src/language-js/loc.js +++ /dev/null @@ -1,107 +0,0 @@ -/** -@import {Node, Comment} from "./types/estree.js"; -*/ - -const isIndex = (value) => Number.isInteger(value) && value >= 0; - -function locStart(node) { - const start = node.range?.[0] ?? node.start; - - /* c8 ignore next 3 */ - if (process.env.NODE_ENV !== "production" && !isIndex(start)) { - throw new TypeError("Can't not locate node."); - } - - // Handle nodes with decorators. They should start at the first decorator - const firstDecorator = (node.declaration?.decorators ?? node.decorators)?.[0]; - if (firstDecorator) { - return Math.min(locStart(firstDecorator), start); - } - - return start; -} - -/** -@param {Node | Comment} node -@return {number} -*/ -function locEnd(node) { - if (node.type === "BreakStatement" || node.type === "ContinueStatement") { - const start = locStart(node); - return node.label - ? locEnd(node.label) - : start + - (node.type === "BreakStatement" ? "break".length : "continue".length); - } - - if (node.type === "DebuggerStatement") { - return locStart(node) + "debugger".length; - } - - if (node.type === "VariableDeclaration") { - const lastDeclaration = node.declarations.at(-1); - return locEnd(lastDeclaration); - } - - if (node.type === "IfStatement") { - return locEnd(node.alternate ?? node.consequent); - } - - if ( - (node.type === "ExpressionStatement" || - node.type === "Directive" || - node.type === "ImportDeclaration" || - node.type === "ExportDefaultDeclaration" || - node.type === "ExportNamedDeclaration" || - node.type === "ExportAllDeclaration" || - node.type === "ReturnStatement" || - node.type === "ThrowStatement") && - node.__contentEnd - ) { - return node.__contentEnd; - } - - return locEndWithFullText(node); -} - -function locEndWithFullText(node) { - const end = node.range?.[1] ?? node.end; - - /* c8 ignore next 3 */ - if (process.env.NODE_ENV !== "production" && !isIndex(end)) { - throw new TypeError("Can't not locate node."); - } - - return end; -} - -/** - * @param {Node} nodeA - * @param {Node} nodeB - * @returns {boolean} - */ -function hasSameLocStart(nodeA, nodeB) { - const nodeAStart = locStart(nodeA); - return isIndex(nodeAStart) && nodeAStart === locStart(nodeB); -} - -/** - * @param {Node} nodeA - * @param {Node} nodeB - * @returns {boolean} - */ -function hasSameLocEnd(nodeA, nodeB) { - const nodeAEnd = locEnd(nodeA); - return isIndex(nodeAEnd) && nodeAEnd === locEnd(nodeB); -} - -/** - * @param {Node} nodeA - * @param {Node} nodeB - * @returns {boolean} - */ -function hasSameLoc(nodeA, nodeB) { - return hasSameLocStart(nodeA, nodeB) && hasSameLocEnd(nodeA, nodeB); -} - -export { hasSameLoc, hasSameLocStart, locEnd, locEndWithFullText, locStart }; diff --git a/src/language-js/location/comparison.js b/src/language-js/location/comparison.js new file mode 100644 index 000000000..c17f2a3fd --- /dev/null +++ b/src/language-js/location/comparison.js @@ -0,0 +1,38 @@ +import { locEnd } from "./end.js"; +import { isIndex } from "./is-index.js"; +import { locStart } from "./start.js"; + +/** +@import {Node, Comment} from "../types/estree.js"; +*/ + +/** + * @param {Node} nodeA + * @param {Node} nodeB + * @returns {boolean} + */ +function hasSameLocStart(nodeA, nodeB) { + const nodeAStart = locStart(nodeA); + return isIndex(nodeAStart) && nodeAStart === locStart(nodeB); +} + +/** + * @param {Node} nodeA + * @param {Node} nodeB + * @returns {boolean} + */ +function hasSameLocEnd(nodeA, nodeB) { + const nodeAEnd = locEnd(nodeA); + return isIndex(nodeAEnd) && nodeAEnd === locEnd(nodeB); +} + +/** + * @param {Node} nodeA + * @param {Node} nodeB + * @returns {boolean} + */ +function hasSameLoc(nodeA, nodeB) { + return hasSameLocStart(nodeA, nodeB) && hasSameLocEnd(nodeA, nodeB); +} + +export { hasSameLoc, hasSameLocStart }; diff --git a/src/language-js/location/end-with-full-text.js b/src/language-js/location/end-with-full-text.js new file mode 100644 index 000000000..080b71886 --- /dev/null +++ b/src/language-js/location/end-with-full-text.js @@ -0,0 +1,23 @@ +import { isIndex } from "./is-index.js"; + +/** +@import {Node, Comment} from "../types/estree.js"; +*/ + +/** +@param {Node | Comment} node +@return {number} +*/ +function locEndWithFullText(node) { + // @ts-expect-error -- safe + const end = node.range?.[1] ?? node.end; + + /* c8 ignore next 3 */ + if (process.env.NODE_ENV !== "production" && !isIndex(end)) { + throw new TypeError("Can't not locate node."); + } + + return end; +} + +export { locEndWithFullText }; diff --git a/src/language-js/location/end.js b/src/language-js/location/end.js new file mode 100644 index 000000000..1c4abb785 --- /dev/null +++ b/src/language-js/location/end.js @@ -0,0 +1,51 @@ +import { locEndWithFullText } from "./end-with-full-text.js"; +import { locStart } from "./start.js"; + +/** +@import {Node, Comment} from "../types/estree.js"; +*/ + +/** +@param {Node | Comment} node +@return {number} +*/ +function locEnd(node) { + if (node.type === "BreakStatement" || node.type === "ContinueStatement") { + const start = locStart(node); + return node.label + ? locEnd(node.label) + : start + + (node.type === "BreakStatement" ? "break".length : "continue".length); + } + + if (node.type === "DebuggerStatement") { + return locStart(node) + "debugger".length; + } + + if (node.type === "VariableDeclaration") { + const lastDeclaration = node.declarations.at(-1); + return locEnd(lastDeclaration); + } + + if (node.type === "IfStatement") { + return locEnd(node.alternate ?? node.consequent); + } + + if ( + (node.type === "ExpressionStatement" || + node.type === "Directive" || + node.type === "ImportDeclaration" || + node.type === "ExportDefaultDeclaration" || + node.type === "ExportNamedDeclaration" || + node.type === "ExportAllDeclaration" || + node.type === "ReturnStatement" || + node.type === "ThrowStatement") && + node.__contentEnd + ) { + return node.__contentEnd; + } + + return locEndWithFullText(node); +} + +export { locEnd }; diff --git a/src/language-js/location/index.js b/src/language-js/location/index.js new file mode 100644 index 000000000..7a7365228 --- /dev/null +++ b/src/language-js/location/index.js @@ -0,0 +1,4 @@ +export { hasSameLoc, hasSameLocStart } from "./comparison.js"; +export { locEnd } from "./end.js"; +export { locEndWithFullText } from "./end-with-full-text.js"; +export { locStart } from "./start.js"; diff --git a/src/language-js/location/is-index.js b/src/language-js/location/is-index.js new file mode 100644 index 000000000..9ef06cd0e --- /dev/null +++ b/src/language-js/location/is-index.js @@ -0,0 +1,3 @@ +const isIndex = (value) => Number.isInteger(value) && value >= 0; + +export { isIndex }; diff --git a/src/language-js/location/start.js b/src/language-js/location/start.js new file mode 100644 index 000000000..f45ac0e4e --- /dev/null +++ b/src/language-js/location/start.js @@ -0,0 +1,30 @@ +import { isIndex } from "./is-index.js"; + +/** +@import {Node, Comment} from "../types/estree.js"; +*/ + +/** +@param {Node | Comment} node +@return {number} +*/ +function locStart(node) { + // @ts-expect-error -- safe + const start = node.range?.[0] ?? node.start; + + /* c8 ignore next 3 */ + if (process.env.NODE_ENV !== "production" && !isIndex(start)) { + throw new TypeError("Can't not locate node."); + } + + // Handle nodes with decorators. They should start at the first decorator + // @ts-expect-error -- safe + const firstDecorator = (node.declaration?.decorators ?? node.decorators)?.[0]; + if (firstDecorator) { + return Math.min(locStart(firstDecorator), start); + } + + return start; +} + +export { locStart }; diff --git a/src/language-js/parse/angular.js b/src/language-js/parse/angular.js index b2bd366fd..89e459606 100644 --- a/src/language-js/parse/angular.js +++ b/src/language-js/parse/angular.js @@ -5,7 +5,7 @@ import { parseTemplateBindings, } from "angular-estree-parser"; import createError from "../../common/parser-create-error.js"; -import { locEnd, locStart } from "../loc.js"; +import { locEnd, locStart } from "../location/index.js"; import wrapExpression from "./utilities/wrap-expression.js"; /** diff --git a/src/language-js/parse/postprocess/index.js b/src/language-js/parse/postprocess/index.js index 4c38fca6f..eb712babd 100644 --- a/src/language-js/parse/postprocess/index.js +++ b/src/language-js/parse/postprocess/index.js @@ -1,6 +1,6 @@ import * as assert from "#universal/assert"; import { commentsPropertyInOptions } from "../../../constants.js"; -import { locEnd, locEndWithFullText, locStart } from "../../loc.js"; +import { locEnd, locEndWithFullText, locStart } from "../../location/index.js"; import { isBlockComment, isLineComment, diff --git a/src/language-js/parse/postprocess/merge-nestled-jsdoc-comments.js b/src/language-js/parse/postprocess/merge-nestled-jsdoc-comments.js index 2052f164c..1d55aa2f3 100644 --- a/src/language-js/parse/postprocess/merge-nestled-jsdoc-comments.js +++ b/src/language-js/parse/postprocess/merge-nestled-jsdoc-comments.js @@ -1,4 +1,4 @@ -import { locEnd, locStart } from "../../loc.js"; +import { locEnd, locStart } from "../../location/index.js"; import { isBlockComment, isLineComment, diff --git a/src/language-js/parse/utilities/create-parser.js b/src/language-js/parse/utilities/create-parser.js index c82a41986..43d1bf66a 100644 --- a/src/language-js/parse/utilities/create-parser.js +++ b/src/language-js/parse/utilities/create-parser.js @@ -1,4 +1,4 @@ -import { locEnd, locStart } from "../../loc.js"; +import { locEnd, locStart } from "../../location/index.js"; import { hasIgnorePragma, hasPragma } from "../../pragma.js"; function createParser(options) { diff --git a/src/language-js/print/array.js b/src/language-js/print/array.js index 1f3310e62..9cc43eec5 100644 --- a/src/language-js/print/array.js +++ b/src/language-js/print/array.js @@ -12,7 +12,7 @@ import hasNewline from "../../utilities/has-newline.js"; import isNextLineEmptyAfterIndex from "../../utilities/is-next-line-empty.js"; import skipInlineComment from "../../utilities/skip-inline-comment.js"; import skipTrailingComment from "../../utilities/skip-trailing-comment.js"; -import { locEnd, locStart } from "../loc.js"; +import { locEnd, locStart } from "../location/index.js"; import { CommentCheckFlags, hasComment } from "../utilities/comments.js"; import { isSignedNumericLiteral } from "../utilities/is-signed-numeric-literal.js"; import { diff --git a/src/language-js/print/class-body.js b/src/language-js/print/class-body.js index 8fab3e45d..b38fce42b 100644 --- a/src/language-js/print/class-body.js +++ b/src/language-js/print/class-body.js @@ -9,7 +9,7 @@ import { import { printDanglingComments } from "../../main/comments/print.js"; import hasNewline from "../../utilities/has-newline.js"; import hasNewlineInRange from "../../utilities/has-newline-in-range.js"; -import { locEnd, locStart } from "../loc.js"; +import { locEnd, locStart } from "../location/index.js"; import { iterateClassMembersPath } from "../utilities/class-members.js"; import { CommentCheckFlags, diff --git a/src/language-js/print/clause.js b/src/language-js/print/clause.js index 81900184c..b8e53b2f1 100644 --- a/src/language-js/print/clause.js +++ b/src/language-js/print/clause.js @@ -1,7 +1,7 @@ import { hardline, indent, line } from "../../document/index.js"; import hasNewline from "../../utilities/has-newline.js"; import hasNewlineInRange from "../../utilities/has-newline-in-range.js"; -import { locEnd, locStart } from "../loc.js"; +import { locEnd, locStart } from "../location/index.js"; import { CommentCheckFlags, getComments, diff --git a/src/language-js/print/comment.js b/src/language-js/print/comment.js index 35897fb63..33bd96cfc 100644 --- a/src/language-js/print/comment.js +++ b/src/language-js/print/comment.js @@ -4,7 +4,7 @@ import { markAsRoot, replaceEndOfLine, } from "../../document/index.js"; -import { locEnd, locStart } from "../loc.js"; +import { locEnd, locStart } from "../location/index.js"; import { isBlockComment, isLineComment } from "../utilities/comment-types.js"; import isIndentableBlockComment from "../utilities/is-indentable-block-comment.js"; diff --git a/src/language-js/print/decorators.js b/src/language-js/print/decorators.js index 1515f07f4..cd8b9c439 100644 --- a/src/language-js/print/decorators.js +++ b/src/language-js/print/decorators.js @@ -7,7 +7,7 @@ import { } from "../../document/index.js"; import hasNewline from "../../utilities/has-newline.js"; import isNonEmptyArray from "../../utilities/is-non-empty-array.js"; -import { hasSameLocStart, locEnd } from "../loc.js"; +import { hasSameLocStart, locEnd } from "../location/index.js"; import isIgnored from "../utilities/is-ignored.js"; import { isExportDeclaration } from "../utilities/node-types.js"; diff --git a/src/language-js/print/function-type.js b/src/language-js/print/function-type.js index e767d7cf6..45a17a6d6 100644 --- a/src/language-js/print/function-type.js +++ b/src/language-js/print/function-type.js @@ -1,5 +1,5 @@ import { group } from "../../document/index.js"; -import { hasSameLocStart } from "../loc.js"; +import { hasSameLocStart } from "../location/index.js"; import { isFlowObjectTypePropertyAFunction } from "../utilities/is-flow-object-type-property-a-function.js"; import { printClassMemberSemicolon } from "./class.js"; import { diff --git a/src/language-js/print/if-statement.js b/src/language-js/print/if-statement.js index 60fb832db..09fa4021e 100644 --- a/src/language-js/print/if-statement.js +++ b/src/language-js/print/if-statement.js @@ -1,7 +1,7 @@ import { group, hardline } from "../../document/index.js"; import { printDanglingComments } from "../../main/comments/print.js"; import hasNewline from "../../utilities/has-newline.js"; -import { locEnd, locStart } from "../loc.js"; +import { locEnd, locStart } from "../location/index.js"; import { CommentCheckFlags, getComments } from "../utilities/comments.js"; import { isPreviousLineEmpty } from "../utilities/is-previous-line-empty.js"; import { needsHardlineAfterDanglingComment } from "../utilities/needs-hardline-after-dangling-comment.js"; diff --git a/src/language-js/print/ignored.js b/src/language-js/print/ignored.js index 8a6cee06d..1f8dd4651 100644 --- a/src/language-js/print/ignored.js +++ b/src/language-js/print/ignored.js @@ -1,6 +1,6 @@ import { indent, softline } from "../../document/index.js"; import isNonEmptyArray from "../../utilities/is-non-empty-array.js"; -import { locEnd, locStart } from "../loc.js"; +import { locEnd, locStart } from "../location/index.js"; import { shouldExpressionStatementPrintLeadingSemicolon } from "../semicolon/semicolon.js"; function printIgnored(path, options /* , print*/) { diff --git a/src/language-js/print/mapped-type.js b/src/language-js/print/mapped-type.js index 4c8b79f12..71c3fea21 100644 --- a/src/language-js/print/mapped-type.js +++ b/src/language-js/print/mapped-type.js @@ -9,7 +9,7 @@ import { import { printDanglingComments } from "../../main/comments/print.js"; import hasNewline from "../../utilities/has-newline.js"; import hasNewlineInRange from "../../utilities/has-newline-in-range.js"; -import { locEnd, locStart } from "../loc.js"; +import { locEnd, locStart } from "../location/index.js"; import { isLineComment } from "../utilities/comment-types.js"; import { CommentCheckFlags, getComments } from "../utilities/comments.js"; import { stripComments } from "../utilities/strip-comments.js"; diff --git a/src/language-js/print/member-chain.js b/src/language-js/print/member-chain.js index 954aa083a..b59ac9779 100644 --- a/src/language-js/print/member-chain.js +++ b/src/language-js/print/member-chain.js @@ -11,7 +11,7 @@ import { import { printComments } from "../../main/comments/print.js"; import getNextNonSpaceNonCommentCharacterIndex from "../../utilities/get-next-non-space-non-comment-character-index.js"; import isNextLineEmptyAfterIndex from "../../utilities/is-next-line-empty.js"; -import { locEnd } from "../loc.js"; +import { locEnd } from "../location/index.js"; import needsParentheses from "../parentheses/needs-parentheses.js"; import { CommentCheckFlags, hasComment } from "../utilities/comments.js"; import { isLongCurriedCallExpression } from "../utilities/is-long-curried-call-expression.js"; diff --git a/src/language-js/print/module.js b/src/language-js/print/module.js index b62798f92..673984dd1 100644 --- a/src/language-js/print/module.js +++ b/src/language-js/print/module.js @@ -10,7 +10,7 @@ import { import { printDanglingComments } from "../../main/comments/print.js"; import isNonEmptyArray from "../../utilities/is-non-empty-array.js"; import UnexpectedNodeError from "../../utilities/unexpected-node-error.js"; -import { locEnd, locStart } from "../loc.js"; +import { locEnd, locStart } from "../location/index.js"; import { CommentCheckFlags, hasComment } from "../utilities/comments.js"; import { createTypeCheckFunction } from "../utilities/create-type-check-function.js"; import { isShorthandSpecifier } from "../utilities/is-shorthand-specifier.js"; diff --git a/src/language-js/print/object.js b/src/language-js/print/object.js index 9a7e57dd8..470bbb7f6 100644 --- a/src/language-js/print/object.js +++ b/src/language-js/print/object.js @@ -10,7 +10,7 @@ import { printDanglingComments } from "../../main/comments/print.js"; import hasNewline from "../../utilities/has-newline.js"; import hasNewlineInRange from "../../utilities/has-newline-in-range.js"; import isNonEmptyArray from "../../utilities/is-non-empty-array.js"; -import { locEnd, locStart } from "../loc.js"; +import { locEnd, locStart } from "../location/index.js"; import { CommentCheckFlags, getComments, diff --git a/src/language-js/print/template-literal.js b/src/language-js/print/template-literal.js index a90e9b1ed..a6f5ebb1d 100644 --- a/src/language-js/print/template-literal.js +++ b/src/language-js/print/template-literal.js @@ -14,7 +14,7 @@ import { import getIndentSize from "../../utilities/get-indent-size.js"; import getStringWidth from "../../utilities/get-string-width.js"; import hasNewlineInRange from "../../utilities/has-newline-in-range.js"; -import { locEnd, locStart } from "../loc.js"; +import { locEnd, locStart } from "../location/index.js"; import { CommentCheckFlags, getComments, diff --git a/src/language-js/print/ternary.js b/src/language-js/print/ternary.js index c8600f777..98a5b46f4 100644 --- a/src/language-js/print/ternary.js +++ b/src/language-js/print/ternary.js @@ -10,7 +10,7 @@ import { } from "../../document/index.js"; import { printDanglingComments } from "../../main/comments/print.js"; import hasNewlineInRange from "../../utilities/has-newline-in-range.js"; -import { locEnd, locStart } from "../loc.js"; +import { locEnd, locStart } from "../location/index.js"; import needsParentheses from "../parentheses/needs-parentheses.js"; import { isBlockComment } from "../utilities/comment-types.js"; import { diff --git a/src/language-js/print/try-statement.js b/src/language-js/print/try-statement.js index 787622582..ae20db2c0 100644 --- a/src/language-js/print/try-statement.js +++ b/src/language-js/print/try-statement.js @@ -1,6 +1,6 @@ import { indent, softline } from "../../document/index.js"; import hasNewline from "../../utilities/has-newline.js"; -import { locEnd, locStart } from "../loc.js"; +import { locEnd, locStart } from "../location/index.js"; import { isBlockComment } from "../utilities/comment-types.js"; import { hasComment } from "../utilities/comments.js"; diff --git a/src/language-js/print/type-parameters.js b/src/language-js/print/type-parameters.js index 02f79f07c..a2d74fc42 100644 --- a/src/language-js/print/type-parameters.js +++ b/src/language-js/print/type-parameters.js @@ -10,7 +10,7 @@ import { } from "../../document/index.js"; import { printDanglingComments } from "../../main/comments/print.js"; import hasNewline from "../../utilities/has-newline.js"; -import { locEnd } from "../loc.js"; +import { locEnd } from "../location/index.js"; import { CommentCheckFlags, hasComment } from "../utilities/comments.js"; import { getFunctionParameters } from "../utilities/function-parameters.js"; import { isObjectType } from "../utilities/node-types.js"; diff --git a/src/language-js/printers.js b/src/language-js/printers.js index 120ff6b71..dd28dc7da 100644 --- a/src/language-js/printers.js +++ b/src/language-js/printers.js @@ -3,7 +3,7 @@ import handleComments from "./comments/handle-comments.js"; import isGap from "./comments/is-gap.js"; import willPrintOwnComments from "./comments/will-print-own-comments.js"; import embed from "./embed/index.js"; -import { locEndWithFullText, locStart } from "./loc.js"; +import { locEndWithFullText, locStart } from "./location/index.js"; import { massageAstNode } from "./massage-ast/index.js"; import { insertPragma } from "./pragma.js"; import { printComment } from "./print/comment.js"; diff --git a/src/language-js/utilities/call-or-new-expression-parentheses.js b/src/language-js/utilities/call-or-new-expression-parentheses.js index ee2b1dad2..c0d487f55 100644 --- a/src/language-js/utilities/call-or-new-expression-parentheses.js +++ b/src/language-js/utilities/call-or-new-expression-parentheses.js @@ -1,4 +1,4 @@ -import { locEnd, locStart } from "../loc.js"; +import { locEnd, locStart } from "../location/index.js"; import { stripComments } from "./strip-comments.js"; /** @@ -36,7 +36,7 @@ function getCallOrNewExpressionClosingParenthesisIndex( /** @param {CallOrNewExpression} callOrNewExpression -@returns {number | void} +@returns {number | undefined} */ function getCallOrNewExpressionOpeningParenthesisIndex( callOrNewExpression, diff --git a/src/language-js/utilities/class-members.js b/src/language-js/utilities/class-members.js index f402b1cc7..3ce32d921 100644 --- a/src/language-js/utilities/class-members.js +++ b/src/language-js/utilities/class-members.js @@ -1,5 +1,5 @@ import isNonEmptyArray from "../../utilities/is-non-empty-array.js"; -import { locStart } from "../loc.js"; +import { locStart } from "../location/index.js"; /** @import AstPath from "../../common/ast-path.js"; diff --git a/src/language-js/utilities/has-leading-own-line-comment.js b/src/language-js/utilities/has-leading-own-line-comment.js index 5b797fe49..8bc5b1e46 100644 --- a/src/language-js/utilities/has-leading-own-line-comment.js +++ b/src/language-js/utilities/has-leading-own-line-comment.js @@ -1,5 +1,5 @@ import hasNewline from "../../utilities/has-newline.js"; -import { locEnd } from "../loc.js"; +import { locEnd } from "../location/index.js"; import { CommentCheckFlags, hasComment } from "./comments.js"; import { hasNodeIgnoreComment } from "./has-node-ignore-comment.js"; import { isJsxElement } from "./node-types.js"; diff --git a/src/language-js/utilities/is-next-line-empty.js b/src/language-js/utilities/is-next-line-empty.js index 9f6f51f71..091f1e260 100644 --- a/src/language-js/utilities/is-next-line-empty.js +++ b/src/language-js/utilities/is-next-line-empty.js @@ -1,5 +1,5 @@ import isNextLineEmptyAfterIndex from "../../utilities/is-next-line-empty.js"; -import { locEnd, locEndWithFullText } from "../loc.js"; +import { locEnd, locEndWithFullText } from "../location/index.js"; /** @import { diff --git a/src/language-js/utilities/is-previous-line-empty.js b/src/language-js/utilities/is-previous-line-empty.js index b20f26ba7..7574feb9d 100644 --- a/src/language-js/utilities/is-previous-line-empty.js +++ b/src/language-js/utilities/is-previous-line-empty.js @@ -1,5 +1,5 @@ import isPreviousLineEmptyBeforeIndex from "../../utilities/is-previous-line-empty.js"; -import { locStart } from "../loc.js"; +import { locStart } from "../location/index.js"; /** @import { diff --git a/src/language-js/utilities/is-shorthand-specifier.js b/src/language-js/utilities/is-shorthand-specifier.js index 6b353774d..e4ebceee8 100644 --- a/src/language-js/utilities/is-shorthand-specifier.js +++ b/src/language-js/utilities/is-shorthand-specifier.js @@ -1,4 +1,4 @@ -import { hasSameLoc } from "../loc.js"; +import { hasSameLoc } from "../location/index.js"; import { getRaw } from "./get-raw.js"; import { isStringLiteral } from "./node-types.js"; diff --git a/src/language-js/utilities/is-template-on-its-own-line.js b/src/language-js/utilities/is-template-on-its-own-line.js index 2d2ae5269..5d46373fa 100644 --- a/src/language-js/utilities/is-template-on-its-own-line.js +++ b/src/language-js/utilities/is-template-on-its-own-line.js @@ -1,5 +1,5 @@ import hasNewline from "../../utilities/has-newline.js"; -import { locStart } from "../loc.js"; +import { locStart } from "../location/index.js"; import { templateLiteralHasNewLines } from "./template-literal-has-new-lines.js"; /** diff --git a/src/language-js/utilities/is-type-annotation-a-function.js b/src/language-js/utilities/is-type-annotation-a-function.js index 71f889190..95b0d1d83 100644 --- a/src/language-js/utilities/is-type-annotation-a-function.js +++ b/src/language-js/utilities/is-type-annotation-a-function.js @@ -1,4 +1,4 @@ -import { hasSameLocStart } from "../loc.js"; +import { hasSameLocStart } from "../location/index.js"; // Hack to differentiate between the following two which have the same ast // declare function f(a): void; diff --git a/src/language-js/utilities/return-statement-has-leading-comment.js b/src/language-js/utilities/return-statement-has-leading-comment.js index a181ded21..ec51ff0d4 100644 --- a/src/language-js/utilities/return-statement-has-leading-comment.js +++ b/src/language-js/utilities/return-statement-has-leading-comment.js @@ -1,5 +1,5 @@ import hasNewlineInRange from "../../utilities/has-newline-in-range.js"; -import { locEnd, locStart } from "../loc.js"; +import { locEnd, locStart } from "../location/index.js"; import { hasLeadingOwnLineComment } from "../utilities/has-leading-own-line-comment.js"; import { CommentCheckFlags, hasComment } from "./comments.js"; import { getLeftSide, hasNakedLeftSide } from "./left-side.js"; diff --git a/src/language-js/utilities/strip-comments.js b/src/language-js/utilities/strip-comments.js index 94d0ac60e..f28bea6ea 100644 --- a/src/language-js/utilities/strip-comments.js +++ b/src/language-js/utilities/strip-comments.js @@ -1,6 +1,6 @@ import { commentsPropertyInOptions } from "../../constants.js"; import replaceNonLineBreaksWithSpace from "../../utilities/replace-non-line-breaks-with-space.js"; -import { locEnd, locStart } from "../loc.js"; +import { locEnd, locStart } from "../location/index.js"; /** @import {Node, Comment} from "../types/estree.js"