evanw / esbuild

An extremely fast bundler for the web
https://esbuild.github.io/
MIT License
38.21k stars 1.15k forks source link

Keep number literals in their original form #3886

Closed wrnrlr closed 3 months ago

wrnrlr commented 3 months ago

Is it possible to keep number literals in their original form? Currently esbuild will turn 1e1 into 10, which is correct of course but in the ganja dialect of javascript this syntax is used as a shorthand for writing multivectors. For example 1e123 is the geometric product of the base vectors 1e1, 1e2 and 1e3.

This is also the behaviour of the toString() of a function:

let f = a => a*1e1
f.toString()
// "(a)=>a * 1e1"
evanw commented 3 months ago

That's a very creative abuse of JavaScript syntax. But at that point that's no longer JavaScript. Sorry, but esbuild only supports real JavaScript not other languages that happen to look like JavaScript but that behave differently. Technically you could say that esbuild doesn't support this because esbuild explicitly doesn't support preserving toString() on functions. But even if that wasn't the problem, you're asking for esbuild to support an obscure programming language that looks like JavaScript but that doesn't behave like it, and that is outside of esbuild's scope. I'm closing this issue as out of scope.