MCPcopy Create free account
hub / github.com/developit/microbundle / toReplacementExpression

Function toReplacementExpression

src/lib/option-normalization.js:5–24  ·  view source on GitHub ↗
(value, name)

Source from the content-addressed store, hash-verified

3 * This is more intuitive than `microbundle --define A=1` producing A="1".
4 */
5export 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.

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…