swc_ecma_transforms_optimization

Function json_parse

source
pub fn json_parse(min_cost: usize) -> impl Pass
Expand description

Transform to optimize performance of literals.

This transform converts pure object literals like

{a: 1, b: 2}

to

JSON.parse('{"a":1, "b"}')

ยงConditions

If any of the conditions below is matched, pure object literal is converter to JSON.parse

  • Object literal is deeply nested (threshold: )

See https://github.com/swc-project/swc/issues/409