ast-kit
Advanced tools
Comparing version 0.11.1 to 0.11.2
@@ -157,2 +157,17 @@ // src/check.ts | ||
// src/loc.ts | ||
function locateTrailingComma(code, start, end, comments = []) { | ||
let i = start; | ||
while (i < end) { | ||
if (comments.some((c) => i >= c.start && i < c.end)) { | ||
i++; | ||
continue; | ||
} | ||
if (code[i] === ",") | ||
return i; | ||
i++; | ||
} | ||
return -1; | ||
} | ||
// src/parse.ts | ||
@@ -196,4 +211,7 @@ import { | ||
function babelParse(code, lang, options = {}) { | ||
const { program, errors } = parse(code, getParserOptions(lang, options)); | ||
return { ...program, errors }; | ||
const { program, errors, comments } = parse( | ||
code, | ||
getParserOptions(lang, options) | ||
); | ||
return { ...program, errors, comments }; | ||
} | ||
@@ -670,2 +688,3 @@ function babelParseExpression(code, lang, options = {}) { | ||
isTypeOf, | ||
locateTrailingComma, | ||
resolveIdentifier, | ||
@@ -672,0 +691,0 @@ resolveLiteral, |
import * as t from '@babel/types'; | ||
import { ParserOptions, ParseResult } from '@babel/parser'; | ||
import { ParseResult as ParseResult$1, ParserOptions } from '@babel/parser'; | ||
import { AttachedScope } from '@rollup/pluginutils'; | ||
@@ -38,2 +38,7 @@ export { AttachedScope } from '@rollup/pluginutils'; | ||
declare function locateTrailingComma(code: string, start: number, end: number, comments?: t.Comment[]): number; | ||
type ParseResult<T> = ParseResult$1<T> & { | ||
comments?: t.Comment[] | null; | ||
}; | ||
declare function babelParse(code: string, lang?: string, options?: ParserOptions): ParseResult<t.Program>; | ||
@@ -90,2 +95,2 @@ declare function babelParseExpression<T extends t.Node = t.Expression>(code: string, lang?: string, options?: ParserOptions): ParseResult<T>; | ||
export { GetNode, ImportBinding, LiteralUnion, NodeType, ObjectPropertyLike, REGEX_DTS, REGEX_LANG_JSX, REGEX_LANG_TS, TS_NODE_TYPES, WithScope, attachScopes, babelParse, babelParseExpression, createStringLiteral, createTSLiteralType, createTSUnionType, escapeKey, getLang, isCallOf, isDts, isFunctionType, isIdentifierOf, isLiteralType, isReferenced, isTs, isTypeOf, resolveIdentifier, resolveLiteral, resolveObjectKey, resolveString, resolveTemplateLiteral, unwrapTSNode, walkAST, walkASTAsync, walkASTSetup, walkImportDeclaration }; | ||
export { GetNode, ImportBinding, LiteralUnion, NodeType, ObjectPropertyLike, ParseResult, REGEX_DTS, REGEX_LANG_JSX, REGEX_LANG_TS, TS_NODE_TYPES, WithScope, attachScopes, babelParse, babelParseExpression, createStringLiteral, createTSLiteralType, createTSUnionType, escapeKey, getLang, isCallOf, isDts, isFunctionType, isIdentifierOf, isLiteralType, isReferenced, isTs, isTypeOf, locateTrailingComma, resolveIdentifier, resolveLiteral, resolveObjectKey, resolveString, resolveTemplateLiteral, unwrapTSNode, walkAST, walkASTAsync, walkASTSetup, walkImportDeclaration }; |
@@ -157,2 +157,17 @@ // src/check.ts | ||
// src/loc.ts | ||
function locateTrailingComma(code, start, end, comments = []) { | ||
let i = start; | ||
while (i < end) { | ||
if (comments.some((c) => i >= c.start && i < c.end)) { | ||
i++; | ||
continue; | ||
} | ||
if (code[i] === ",") | ||
return i; | ||
i++; | ||
} | ||
return -1; | ||
} | ||
// src/parse.ts | ||
@@ -196,4 +211,7 @@ import { | ||
function babelParse(code, lang, options = {}) { | ||
const { program, errors } = parse(code, getParserOptions(lang, options)); | ||
return { ...program, errors }; | ||
const { program, errors, comments } = parse( | ||
code, | ||
getParserOptions(lang, options) | ||
); | ||
return { ...program, errors, comments }; | ||
} | ||
@@ -670,2 +688,3 @@ function babelParseExpression(code, lang, options = {}) { | ||
isTypeOf, | ||
locateTrailingComma, | ||
resolveIdentifier, | ||
@@ -672,0 +691,0 @@ resolveLiteral, |
{ | ||
"name": "ast-kit", | ||
"version": "0.11.1", | ||
"packageManager": "pnpm@8.7.0", | ||
"version": "0.11.2", | ||
"packageManager": "pnpm@8.7.1", | ||
"description": "AST Toolkit.", | ||
@@ -33,3 +33,3 @@ "type": "module", | ||
"dependencies": { | ||
"@babel/parser": "^7.22.11", | ||
"@babel/parser": "^7.22.14", | ||
"@rollup/pluginutils": "^5.0.4", | ||
@@ -40,5 +40,5 @@ "pathe": "^1.1.1" | ||
"@babel/types": "^7.22.11", | ||
"@sxzz/eslint-config": "^3.4.0", | ||
"@sxzz/eslint-config": "^3.5.1", | ||
"@sxzz/prettier-config": "^1.0.4", | ||
"@types/node": "^20.5.7", | ||
"@types/node": "^20.5.9", | ||
"@vitest/coverage-v8": "^0.34.3", | ||
@@ -50,5 +50,5 @@ "@vitest/ui": "^0.34.3", | ||
"fast-glob": "^3.3.1", | ||
"prettier": "^3.0.2", | ||
"prettier": "^3.0.3", | ||
"tsup": "^7.2.0", | ||
"tsx": "^3.12.7", | ||
"tsx": "^3.12.8", | ||
"typescript": "^5.2.2", | ||
@@ -55,0 +55,0 @@ "vitest": "^0.34.3" |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
75146
2155
Updated@babel/parser@^7.22.14