What can be the reason that a project works in `br...
# javascript
a
What can be the reason that a project works in
browserDevelopmentRun
but not in
browserProductionRun
/
browserDistribution
. I made this toy programming language using the excellent parser combinator library
better-parser
but now run into the issue that development and production builds produce different results: https://github.com/h0tk3y/better-parse/issues/66
a
The key difference between prod and dev that in production all unused in Kotlin declarations will be removed. What version of the compiler do you use?
a
I use 1.9.0
I tried different versions, even back to 1.6.20 but all to no avail
a
Hmm
I'll try to reproduce it and will provide an update as soon as I find something.
a
I have the feeling it is maybe related to DCE, but need to check.
In my code, I output as a test the tokens from the tokenizer. In production I get more tokens than in development for the following code:
Copy code
fn fib = (n) ->  {
  if (n < 2) n else fib(n - 1) + fib(n - 2)
}

fib(10)
a
It could be DCE, but only in case if you define something without explicit usage in the Kotlin codebase. I need to check it
a
I made a basic nodejs sample:
Copy code
fun main() {
    val input = "fn foo = (n) -> { n }"
    val tokens = DefaultTokenizer(Tokens).tokenize(input).toList()
    println(tokens)
}
This results in the following tokens: Development
Copy code
[fn@1 for "fn" at 0 (1:1), whitespace@2 for " " at 2 (1:3), identifier@3 for "foo" at 3 (1:4), whitespace@4 for " " at 6 (1:7), equal@5 for "=" at 7 (1:8), whitespace@6 for " " at 8 (1:9), leftParenthesis@7 for "(" at 9 (1:10), identifier@8 for "n" at 10 (1:11), rightParenthesis@9 for ")" at 11 (1:12), whitespace@10 for " " at 12 (1:13), rightArrow@11 for "->" at 13 (1:14), whitespace@12 for " " at 15 (1:16), leftBrace@13 for "{" at 16 (1:17), whitespace@14 for " " at 17 (1:18), identifier@15 for "n" at 18 (1:19), whitespace@16 for " " at 19 (1:20), rightBrace@17 for "}" at 20 (1:21)]
Production
Copy code
[whitespace@1 for "f" at 0 (1:1), whitespace@2 for "n" at 1 (1:2), whitespace@3 for " " at 2 (1:3), whitespace@4 for "f" at 3 (1:4), whitespace@5 for "o" at 4 (1:5), whitespace@6 for "o" at 5 (1:6), whitespace@7 for " " at 6 (1:7), whitespace@8 for "=" at 7 (1:8), whitespace@9 for " " at 8 (1:9), whitespace@10 for "(" at 9 (1:10), whitespace@11 for "n" at 10 (1:11), whitespace@12 for ")" at 11 (1:12), whitespace@13 for " " at 12 (1:13), whitespace@14 for "-" at 13 (1:14), whitespace@15 for ">" at 14 (1:15), whitespace@16 for " " at 15 (1:16), whitespace@17 for "{" at 16 (1:17), whites
The tokenizer is absolutely broken with JS production built
I found the cause, the order of tokens passed to the tokenizer is important of course, but these rules differ between development and production builds....
However, I can't fix it. It appears to be caused by the regexToken
I've fixed it in the code of
better-parse
and created a Pull Request. It is a faulty Regex implementation. Why or how it doesn't work between dev and prod is a mystery to me for now. However, when moving to the Jetbrains Regex common implementation, everything works.
👀 1