Welcome! Please see the About page for a little more info on how this works.

0 votes
in ClojureScript by

(def x x)

This code executes fine in JS but does not produce anything useful and I wonder if we should check for this. When running {{:advanced}} compilation it will fail with a cryptic error message like:

`
Exception in thread "main" java.lang.IllegalStateException: ASSIGN 5 [length: 23] [source_file: .../test/foo.js] is not the parent of GETPROP 5 [length: 10] [source_file: .../test/foo.js]

    at com.google.common.base.Preconditions.checkState(Preconditions.java:733)
    at com.google.javascript.rhino.Node.replaceChild(Node.java:900)
    at com.google.javascript.jscomp.AggressiveInlineAliases.inlineGlobalAliasIfPossible(AggressiveInlineAliases.java:557)
    at com.google.javascript.jscomp.AggressiveInlineAliases.inlineAliases(AggressiveInlineAliases.java:180)
    at com.google.javascript.jscomp.AggressiveInlineAliases.process(AggressiveInlineAliases.java:123)
    at com.google.javascript.jscomp.PhaseOptimizer$NamedPass.process(PhaseOptimizer.java:303)
    at com.google.javascript.jscomp.PhaseOptimizer.process(PhaseOptimizer.java:230)
    at com.google.javascript.jscomp.Compiler.performOptimizations(Compiler.java:2480)
    at com.google.javascript.jscomp.Compiler$3.call(Compiler.java:808)
    at com.google.javascript.jscomp.Compiler$3.call(Compiler.java:804)
    at com.google.javascript.jscomp.CompilerExecutor$2.call(CompilerExecutor.java:102)
    at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
    at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1135)
    at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
    at java.base/java.lang.Thread.run(Thread.java:844)

`

The code is unusable anyways and probably always written by mistake. This mistake came up a couple of times when shadow-cljs users migrated some code from CLJSJS that used to pull some global into the local namespace.

`
(ns demo.foo
(:require [cljsjs.foo]))

(def foo js/foo)
`

rewritten to

`
(ns demo.foo
(:require ["that-npm-foo" :as foo]))

(def foo foo)
`

The mistake made is thinking that the RHS of the {{def}} refers to the ns alias {{foo}} but it actually refers to the LHS.

1 Answer

0 votes
by
Reference: https://clojure.atlassian.net/browse/CLJS-2851 (reported by thheller)
...