11import { Identifier , Literal , SourceLocation , Node , Position as EsPosition } from 'estree' ;
2- import { AUTOCOMPLETE_TYPES , Chapter , Context , DeclarationKind , DECLARATIONS , DeclarationSymbol , Documentation , ImportedSymbol , NODES , ParameterSymbol } from "./types" ;
2+ import { AUTOCOMPLETE_TYPES , Chapter , Context , DeclarationKind , DECLARATIONS , DeclarationSymbol , Documentation , EXPRESSIONS , ImportedSymbol , NODES , ParameterSymbol } from "./types" ;
33import { autocomplete_labels , builtin_constants , builtin_functions , esPosInSourceLoc , findLastRange , getImportedName , getNodeChildren , isBuiltinConst , isBuiltinFunction , mapDeclarationSymbolToDocumentSymbol , mapMetaToCompletionItemKind , module_autocomplete , moduleExists , rangeToSourceLoc , sourceLocEquals , sourceLocInSourceLoc , sourceLocToRange , vsPosInSourceLoc , vsPosToEsPos } from "./utils" ;
44import { CompletionItem , Diagnostic , DiagnosticSeverity , DiagnosticTag , DocumentHighlight , DocumentSymbol , Hover , Position , Range , TextEdit , WorkspaceEdit } from "vscode-languageserver" ;
55import { parse as acornParse , Options } from 'acorn' ;
6- import { parse as looseParse } from 'acorn-loose' ;
6+ import { parse as looseParse } from 'acorn-loose' ;
77import { rules , bannedNodes } from "./rules" ;
88
99export const DEFAULT_ECMA_VERSION = 6 ;
@@ -54,7 +54,7 @@ export class AST {
5454 catch ( e ) {
5555 this . ast = looseParse ( text , acornOptions ) as Node
5656 }
57- // console.debug(JSON.stringify(this.ast, null, 2));
57+ console . debug ( JSON . stringify ( this . ast , null , 2 ) ) ;
5858
5959 this . context = context ;
6060 this . uri = uri ;
@@ -164,7 +164,7 @@ export class AST {
164164 const variableDeclaration : DeclarationSymbol = {
165165 name : name ,
166166 scope : parent . loc ! ,
167- meta : child . kind === "var" || child . kind === "let" ? "let" : "const" ,
167+ meta : child . kind === "var" || child . kind === "let" ? "let" : declaration . init ?. type === EXPRESSIONS . LAMBDA ? "func" : "const" ,
168168 declarationKind : child . kind === "var" || child . kind === "let" ? DeclarationKind . KIND_LET : DeclarationKind . KIND_CONST ,
169169 range : sourceLocToRange ( declaration . loc ! ) ,
170170 selectionRange : sourceLocToRange ( declaration . id . loc ! ) ,
@@ -173,9 +173,9 @@ export class AST {
173173 this . addDeclaration ( name , variableDeclaration ) ;
174174
175175
176- if ( declaration . init && declaration . init . type == DECLARATIONS . LAMBDA ) {
176+ if ( declaration . init && declaration . init . type == EXPRESSIONS . LAMBDA ) {
177177 const lambda = declaration . init ;
178- if ( lambda . params . length !== 0 ) variableDeclaration . parameters = [ ] ;
178+ variableDeclaration . parameters = [ ] ;
179179
180180 lambda . params . forEach ( param => {
181181 if ( param . loc ) {
@@ -252,9 +252,13 @@ export class AST {
252252 } )
253253 }
254254 // Handle anonymous lambdas
255- else if ( child . type === DECLARATIONS . LAMBDA && parent . type !== DECLARATIONS . VARIABLE ) {
255+ else if ( child . type === EXPRESSIONS . LAMBDA && parent . type !== DECLARATIONS . VARIABLE ) {
256256 child . params . forEach ( param => {
257- const name = ( param as Identifier ) . name ;
257+ let name = "" ;
258+ if ( param . type === NODES . IDENTIFIER )
259+ name = param . name
260+ else if ( param . type === NODES . REST && param . argument . type === NODES . IDENTIFIER )
261+ name = param . argument . name
258262 const param_declaration : DeclarationSymbol = {
259263 name : name ,
260264 scope : child . body . loc ! ,
@@ -340,7 +344,7 @@ export class AST {
340344
341345 getNodeChildren ( node , true ) . forEach ( node => {
342346 if (
343- scopeFound
347+ scopeFound
344348 // We want to ignore scopes where the variable was redeclared
345349 // This occurs when there is an inner scope in the scope of our declaration, and the child node belongs in that scope
346350 && ! this . declarations . get ( identifier . name ) ?. some ( x => ! sourceLocEquals ( x . scope , declaration . scope ) && sourceLocInSourceLoc ( x . scope , declaration . scope ) && sourceLocInSourceLoc ( node . loc ! , x . scope ) )
0 commit comments