MCPcopy Index your code
hub / github.com/developit/htm / spreadNode

Function spreadNode

packages/babel-plugin-htm/index.mjs:124–156  ·  view source on GitHub ↗
(args, state)

Source from the content-addressed store, hash-verified

122 }
123
124 function spreadNode(args, state) {
125 if (args.length === 0) {
126 return t.nullLiteral();
127 }
128 if (args.length > 0 && t.isNode(args[0])) {
129 args.unshift({});
130 }
131
132 // 'Object.assign(x)', can be collapsed to 'x'.
133 if (args.length === 1) {
134 return propsNode(args[0]);
135 }
136 // 'Object.assign({}, x)', can be collapsed to 'x'.
137 if (args.length === 2 && !t.isNode(args[0]) && Object.keys(args[0]).length === 0) {
138 return propsNode(args[1]);
139 }
140
141 if (useNativeSpread) {
142 const properties = [];
143 args.forEach(arg => {
144 if (t.isNode(arg)) {
145 properties.push(t.spreadElement(arg));
146 }
147 else {
148 properties.push(...objectProperties(arg));
149 }
150 });
151 return t.objectExpression(properties);
152 }
153
154 const helper = useBuiltIns ? dottedIdentifier('Object.assign') : state.addHelper('extends');
155 return t.callExpression(helper, args.map(propsNode));
156 }
157
158 function propsNode(props) {
159 return t.isNode(props) ? props : t.objectExpression(objectProperties(props));

Callers 1

transformFunction · 0.85

Calls 3

propsNodeFunction · 0.85
objectPropertiesFunction · 0.85
dottedIdentifierFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…