closes#273closes#814
HIR is removed from this PR, with the minifier being commented out.
HIR is a wonderful idea for compiling to lower languages, but after
sitting on it for a few months I found that it only adds confusion and
uncertainties to both myself and future contributors.
It also adds too much burden to maintainers if we plan to support more
downstream tools.
1 AST is the only way.
Fold constant addition expressions. Handles string concatenation and
addition, both with implicit casting.
For example,
```ts
let x = 1 + 1
let y = "hello " + "world"
```
now becomes
```ts
let x = 2
let y = "hello world"
```
## Extra Goodies
- test(minifier): add `test_snapshot` helper to perform snapshot tests
with `insta`
- up(hir): implement `std::ops::Add` for `NumericValue`
- up(span): impl `TryFrom<Cow<'_, &str>>` for `Atom`
When initially written types were not in the symbol table. Now that
types are in the symbol table it makes sense given
```ts
type A = 1
type B = A
```
that you can get to the symbol id for for A from type B = A.
Please correct me if I'm wrong about how I implemented this. I also
verified that occurrence (I believe this is the correct word) behaves
how I would expect.
```ts
type RecursiveType = string | {[x: string]: RecursiveType}
```
Does populate a reference.
---------
Co-authored-by: Boshen <boshenc@gmail.com>
# 1. Support join('\n')
I'm trying to run `just new-rule no-unexpected-multiline`, It found
rulegen not support test code pieced together using `array.json("\n")`,
like
```js
{
code: [
"const x = aaaa<",
" test",
">/*",
"test",
"*/`foo`"
].join("\n")
}
```
I found this kind of code widely in the eslint codebase, so it will be
great if we can support this.

# 2. remove extra `,`
And I found when meet unsupported code, rulegen will generate an extra
`,`, so I added a filter at
45cf5fc3da/tasks/rulegen/src/main.rs (L363)
# 3. handle escape string
The escape `/` and trailing `/` in the javascript code will break
rulegen. example: `"\"abc\\\n(123)\""`
I made the following changes:
```diff
- test_code.replace('\n', "\n\t\t\t")
+ test_code.replace('\n', "\n\t\t\t").replace('\\', "\\\\").replace('\"', "\\\"")
```
For #634.
This PR prepares for the fix of #634, adding an option to formatter to
control whether to quote object properties. After this PR, the rulegen
script can use oxc-formatter to output JSON-like object literal.
The `Quote Props` option is from Prettier. For detail:
https://prettier.io/docs/en/options.html#quote-props
> Change when properties in objects are quoted.
> Valid options:
> "as-needed" - Only add quotes around object properties where required.
> "consistent" - If at least one property in an object requires quotes,
quote all properties.
> "preserve" - Respect the input use of quotes in object properties.
---------
Co-authored-by: Don Isaac <donald.isaac@gmail.com>