ClojureScript

Warn about reserved JS keyword usage in namespace names

Details

  • Type: Defect Defect
  • Status: Open Open
  • Priority: Major Major
  • Resolution: Unresolved
  • Affects Version/s: None
  • Fix Version/s: None
  • Component/s: None
  • Labels:
    None

Description

If a namespace is identified as foo.long.core it will get munged into foo.long$.core. This is unexpected and a source of confusion when goog.require("foo.long.core") fails.

Activity

David Nolen made changes -
Field Original Value New Value
Description If a namespace is identified as {{foo.long.core}} it will get munged into {{foo.long$.core}}. This is unexpected and an source of confusion when {{goog.require("foo.long.core")}} fails. If a namespace is identified as {{foo.long.core}} it will get munged into {{foo.long$.core}}. This is unexpected and a source of confusion when {{goog.require("foo.long.core")}} fails.
Hide
Max Veytsman added a comment -

I'm starting to take a look at this.

Would it be most appropriate to add this check into compiler.cljs where the munging actually happens, or into analyzer.cljs where most of the warnings of this type live?

Show
Max Veytsman added a comment - I'm starting to take a look at this. Would it be most appropriate to add this check into compiler.cljs where the munging actually happens, or into analyzer.cljs where most of the warnings of this type live?
Hide
Mike Fikes added a comment -

If a solution is identified that eliminates “overly aggressive” munging for certain cases, then CLJS-689 could benefit.

Show
Mike Fikes added a comment - If a solution is identified that eliminates “overly aggressive” munging for certain cases, then CLJS-689 could benefit.
Hide
Max Veytsman added a comment - - edited

Currently, when munging "foo.bar.baz", we map over ["foo", "bar", "baz"] and check if each is a reserved word (https://github.com/clojure/clojurescript/blob/master/src/clj/cljs/compiler.clj#L94-L95)

According to my understanding of https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Lexical_grammar#Reserved_word_usage and https://es5.github.io/#x7.6 reserved words are only disallowed in Identifiers. MemberExpressions and CallExpressions (the things with "."s in them) do not ban reserved words except in the first Identifier.

For our purposes, it could be enough to check if the entire token and the first period-seperated element is reserved. I.e. long becomes long$, long.night.ahead becomes long$.night.ahead, but foo.long.core remains foo.long.core.

Mike, this unfortunately won't affect CLJS-689

Does that sound like a good approach?

Show
Max Veytsman added a comment - - edited Currently, when munging "foo.bar.baz", we map over ["foo", "bar", "baz"] and check if each is a reserved word (https://github.com/clojure/clojurescript/blob/master/src/clj/cljs/compiler.clj#L94-L95) According to my understanding of https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Lexical_grammar#Reserved_word_usage and https://es5.github.io/#x7.6 reserved words are only disallowed in Identifiers. MemberExpressions and CallExpressions (the things with "."s in them) do not ban reserved words except in the first Identifier. For our purposes, it could be enough to check if the entire token and the first period-seperated element is reserved. I.e. long becomes long$, long.night.ahead becomes long$.night.ahead, but foo.long.core remains foo.long.core. Mike, this unfortunately won't affect CLJS-689 Does that sound like a good approach?

People

Vote (0)
Watch (3)

Dates

  • Created:
    Updated: