tomblachut / svelte-intellij

Svelte components in WebStorm and friends
MIT License
485 stars 38 forks source link

Handle $$props etc variable shadowing #144

Closed tomblachut closed 1 year ago

tomblachut commented 4 years ago

https://svelte.dev/repl/1e78f2cd120247a9899d3a525675c836?version=3.24.1

Such variables need to be checked after reaching script tag, right now they are checked - by name - at the very beginning of reference resolving.

shirotech commented 4 years ago

I think this is a bug in Svelte itself to allow it, if we put this on the main scope, e.g.

const {name: $$props} = cats[0];

The compiler will complain The $ prefix is reserved, and cannot be used for variable and import names (...)

tomblachut commented 4 years ago

But if you create event handler with $$props: Event as an argument, will it complain? I think not.

My current understanding is that this code

        implicitIdentifiers.forEach {
            if (JSSymbolUtil.isAccurateReferenceExpressionName(expression, it)) {
                val element = JSImplicitElementImpl.Builder(it, expression)
                    .forbidAstAccess()
                    .setType(JSImplicitElement.Type.Variable)
                    .setProperties(JSImplicitElement.Property.Constant)
                    .toImplicitElement()
                return arrayOf(JSResolveResult(element))
            }
        }

should be adapted and placed in SvelteHtmlFile#processDeclarations, after processing both script tags.

tomblachut commented 1 year ago

Moving to WEB-62304 Svelte: improve local reference resolve