(value, name)
| 3 | * This is more intuitive than `microbundle --define A=1` producing A="1". |
| 4 | */ |
| 5 | export function toReplacementExpression(value, name) { |
| 6 | // --define A="1",B='true' produces string: |
| 7 | const matches = value.match(/^(['"])(.+)\1$/); |
| 8 | if (matches) { |
| 9 | return [JSON.stringify(matches[2]), name]; |
| 10 | } |
| 11 | |
| 12 | // --define @assign=Object.assign replaces expressions with expressions: |
| 13 | if (name[0] === '@') { |
| 14 | return [value, name.substring(1)]; |
| 15 | } |
| 16 | |
| 17 | // --define A=1,B=true produces int/boolean literal: |
| 18 | if (/^(true|false|\d+)$/i.test(value)) { |
| 19 | return [value, name]; |
| 20 | } |
| 21 | |
| 22 | // default: string literal |
| 23 | return [JSON.stringify(value), name]; |
| 24 | } |
| 25 | |
| 26 | /** |
| 27 | * Parses values of the form "$=jQuery,React=react" into key-value object pairs. |
nothing calls this directly
no outgoing calls
no test coverage detected
searching dependent graphs…