Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
so1ve committed May 7, 2024
1 parent 2d41aa8 commit f027ce5
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 13 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"private": true,
"packageManager": "pnpm@9.0.0",
"packageManager": "pnpm@9.1.0",
"scripts": {
"build": "tsc -b",
"watch": "npm run build && (npm run watch:base & npm run watch:vue)",
Expand Down
20 changes: 8 additions & 12 deletions packages/language-core/lib/utils/parseBindings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,7 @@ export function parseBindings(ts: typeof import('typescript'), sourceFile: ts.So
}
// { foo } = ...
else if (ts.isShorthandPropertyAssignment(_node)) {
const nodeText = _getNodeText(_node.name);
bindingRanges.push(_getStartEnd(_node.name));
bindingTypes.set(nodeText, BindingTypes.NeedUnref);
addBinding(_node.name, BindingTypes.NeedUnref);
}
// { ...? } = ...
// [ ...? ] = ...
Expand All @@ -117,9 +115,7 @@ export function parseBindings(ts: typeof import('typescript'), sourceFile: ts.So
|| ts.isEnumDeclaration(node)
) {
if (node.name) {
const nodeText = _getNodeText(node.name);
bindingRanges.push(_getStartEnd(node.name));
bindingTypes.set(nodeText, BindingTypes.NoUnref);
addBinding(node.name, BindingTypes.NoUnref);
}
}
else if (ts.isImportDeclaration(node)) {
Expand All @@ -137,15 +133,11 @@ export function parseBindings(ts: typeof import('typescript'), sourceFile: ts.So
if (node.importClause.namedBindings) {
if (ts.isNamedImports(node.importClause.namedBindings)) {
for (const element of node.importClause.namedBindings.elements) {
const nodeText = _getNodeText(element.name);
bindingRanges.push(_getStartEnd(element.name));
bindingTypes.set(nodeText, BindingTypes.NeedUnref);
addBinding(element.name, BindingTypes.NeedUnref);
}
}
else if (ts.isNamespaceImport(node.importClause.namedBindings)) {
const nodeText = _getNodeText(node.importClause.namedBindings.name);
bindingRanges.push(_getStartEnd(node.importClause.namedBindings.name));
bindingTypes.set(nodeText, BindingTypes.NoUnref);
addBinding(node.importClause.namedBindings.name, BindingTypes.NoUnref);
}
}
}
Expand All @@ -159,6 +151,10 @@ export function parseBindings(ts: typeof import('typescript'), sourceFile: ts.So
function _getNodeText(node: ts.Node) {
return getNodeText(ts, node, sourceFile);
}
function addBinding(node: ts.Node, bindingType: BindingTypes) {
bindingRanges.push(_getStartEnd(node));
bindingTypes.set(_getNodeText(node), bindingType);
}
function getInnerExpression(node: ts.Node) {
if (isAsExpression(node) || ts.isSatisfiesExpression(node) || ts.isParenthesizedExpression(node)) {
return getInnerExpression(node.expression);
Expand Down

0 comments on commit f027ce5

Please sign in to comment.