Comparing version 0.0.16 to 0.0.17
# code-red changelog | ||
## 0.0.17 | ||
* Fixes and additions | ||
## 0.0.16 | ||
@@ -4,0 +8,0 @@ |
@@ -218,3 +218,3 @@ (function (global, factory) { | ||
...state, | ||
indent: state.indent + '\t' | ||
indent: state.indent + (node.declarations.length === 1 ? '' : '\t') | ||
})); | ||
@@ -227,10 +227,6 @@ | ||
const separator = c(multiple_lines ? `,\n${state.indent}` : ', '); | ||
const separator = c(multiple_lines ? `,\n${state.indent}\t` : ', '); | ||
if (multiple_lines) { | ||
chunks.push( | ||
c(`\n${state.indent}\t`), | ||
...join(declarators, separator), | ||
c(`\n${state.indent}`) | ||
); | ||
chunks.push(...join(declarators, separator)); | ||
} else { | ||
@@ -309,15 +305,53 @@ chunks.push( | ||
BreakStatement(node, state) { | ||
throw new Error(`TODO BreakStatement`); | ||
return node.label | ||
? [c('break '), ...handle(node.label, state), c(';')] | ||
: [c('break;')]; | ||
}, | ||
ContinueStatement(node, state) { | ||
throw new Error(`TODO ContinueStatement`); | ||
return node.label | ||
? [c('continue '), ...handle(node.label, state), c(';')] | ||
: [c('continue;')]; | ||
}, | ||
WithStatement(node, state) { | ||
throw new Error(`TODO WithStatement`); | ||
return [ | ||
c('with ('), | ||
...handle(node.object, state), | ||
c(') '), | ||
...handle(node.body, state) | ||
]; | ||
}, | ||
SwitchStatement(node, state) { | ||
throw new Error(`TODO SwitchStatement`); | ||
const chunks = [ | ||
c('switch ('), | ||
...handle(node.discriminant, state), | ||
c(') {') | ||
]; | ||
const child_state = { ...state, indent: `${state.indent}\t\t` }; | ||
node.cases.forEach(block => { | ||
if (block.test) { | ||
chunks.push( | ||
c(`\n${state.indent}\tcase `), | ||
...handle(block.test, { ...state, indent: `${state.indent}\t` }), | ||
c(':') | ||
); | ||
} else { | ||
chunks.push(c(`\n${state.indent}\tdefault:`)); | ||
} | ||
block.consequent.forEach(statement => { | ||
chunks.push( | ||
c(`\n${state.indent}\t\t`), | ||
...handle(statement, { ...state, indent: `${state.indent}\t\t` }) | ||
); | ||
}); | ||
}); | ||
chunks.push(c(`\n${state.indent}}`)); | ||
return chunks; | ||
}, | ||
@@ -346,3 +380,26 @@ | ||
TryStatement(node, state) { | ||
throw new Error(`TODO TryStatement`); | ||
const chunks = [ | ||
c('try '), | ||
...handle(node.block, state) | ||
]; | ||
if (node.handler) { | ||
if (node.handler.param) { | ||
chunks.push( | ||
c(' catch('), | ||
...handle(node.handler.param, state), | ||
c(') ') | ||
); | ||
} else { | ||
chunks.push(c(' catch ')); | ||
} | ||
chunks.push(...handle(node.handler.body, state)); | ||
} | ||
if (node.finalizer) { | ||
chunks.push(c(' finally '), ...handle(node.finalizer, state)); | ||
} | ||
return chunks; | ||
}, | ||
@@ -560,2 +617,6 @@ | ||
ImportExpression(node, state) { | ||
return [c('import('), ...handle(node.source, state), c(')')]; | ||
}, | ||
ExportDefaultDeclaration(node, state) { | ||
@@ -722,3 +783,7 @@ const chunks = [ | ||
YieldExpression(node, state) { | ||
throw new Error(`TODO YieldExpression`); | ||
if (node.argument) { | ||
return [c(node.delegate ? `yield* ` : `yield `), ...handle(node.argument, state)]; | ||
} | ||
return [c(node.delegate ? `yield*` : `yield`)]; | ||
}, | ||
@@ -757,3 +822,3 @@ | ||
TaggedTemplateExpression(node, state) { | ||
throw new Error(`TODO TaggedTemplateExpression`); | ||
return handle(node.tag, state).concat(handle(node.quasi, state)); | ||
}, | ||
@@ -814,3 +879,3 @@ | ||
properties.some(has_newline) || | ||
(properties.map(get_length).reduce(sum, 0) + (state.indent.length + properties.length - 1) * 2) > 80 | ||
(properties.map(get_length).reduce(sum, 0) + (state.indent.length + properties.length - 1) * 2) > 40 | ||
); | ||
@@ -834,2 +899,12 @@ | ||
// special case | ||
if ( | ||
!node.computed && | ||
node.value.type === 'AssignmentPattern' && | ||
node.value.left.type === 'Identifier' && | ||
node.value.left.name === (node.key ).name | ||
) { | ||
return value; | ||
} | ||
const key = handle(node.key, state); | ||
@@ -847,4 +922,8 @@ | ||
return [ | ||
...key, | ||
const chunks = node.kind !== 'init' | ||
? [c(`${node.kind} `)] | ||
: []; | ||
chunks.push( | ||
...(node.computed ? [c('['), ...key, c(']')] : key), | ||
c('('), | ||
@@ -854,7 +933,5 @@ ...join((node.value ).params.map(param => handle(param, state)), c(', ')), | ||
...handle((node.value ).body, state) | ||
]; | ||
} | ||
); | ||
if (node.kind !== 'init') { | ||
throw new Error(`TODO ${node.kind}`); | ||
return chunks; | ||
} | ||
@@ -1073,17 +1150,26 @@ | ||
const args = node.arguments.map(arg => handle(arg, { | ||
...state, | ||
indent: state.indent + '\t' | ||
})); | ||
const args = node.arguments.map(arg => handle(arg, state)); | ||
const separator = args.some(has_newline) // TODO or length exceeds 80 | ||
? c(',\n' + state.indent) | ||
: c(', '); | ||
const multiple_lines = args.slice(0, -1).some(has_newline); // TODO or length exceeds 80 | ||
chunks.push( | ||
c('('), | ||
...join(args, separator) , | ||
c(')') | ||
); | ||
if (multiple_lines) { | ||
// need to handle args again. TODO find alternative approach? | ||
const args = node.arguments.map(arg => handle(arg, { | ||
...state, | ||
indent: `${state.indent}\t` | ||
})); | ||
chunks.push( | ||
c(`(\n${state.indent}\t`), | ||
...join(args, c(`,\n${state.indent}\t`)), | ||
c(`\n${state.indent})`) | ||
); | ||
} else { | ||
chunks.push( | ||
c('('), | ||
...join(args, c(', ')), | ||
c(')') | ||
); | ||
} | ||
return chunks; | ||
@@ -1122,3 +1208,3 @@ }, | ||
MetaProperty(node, state) { | ||
throw new Error(`TODO MetaProperty`); | ||
return [...handle(node.meta, state), c('.'), ...handle(node.property, state)]; | ||
}, | ||
@@ -1155,5 +1241,8 @@ | ||
Literal(node, state) { | ||
// TODO | ||
if (typeof node.value === 'string') { | ||
return [c(JSON.stringify(node.value), node)]; | ||
return [ | ||
// TODO do we need to handle weird unicode characters somehow? | ||
// str.replace(/\\u(\d{4})/g, (m, n) => String.fromCharCode(+n)) | ||
c(JSON.stringify(node.value), node) | ||
]; | ||
} | ||
@@ -1167,7 +1256,3 @@ | ||
return [c(String(node.value), node)]; | ||
}, | ||
RegExpLiteral(node, state) { | ||
throw new Error(`TODO RegExpLiteral`); | ||
}, | ||
} | ||
}; | ||
@@ -1422,7 +1507,7 @@ | ||
const ast = acorn.parse(str, { | ||
ecmaVersion: 2019, | ||
ecmaVersion: 11, | ||
sourceType: 'module', | ||
allowAwaitOutsideFunction: true, | ||
allowReturnOutsideFunction: true | ||
}); | ||
} ); | ||
@@ -1442,5 +1527,7 @@ inject(ast, values); | ||
const expression = acorn.parseExpressionAt(str, 0, { | ||
ecmaVersion: 11, | ||
sourceType: 'module', | ||
allowAwaitOutsideFunction: true, | ||
allowImportExportEverywhere: true | ||
}) ; | ||
} ) ; | ||
@@ -1460,5 +1547,7 @@ inject(expression, values); | ||
const expression = acorn.parseExpressionAt(str, 0, { | ||
ecmaVersion: 11, | ||
sourceType: 'module', | ||
allowAwaitOutsideFunction: true, | ||
allowImportExportEverywhere: true | ||
}) ; | ||
} ) ; | ||
@@ -1465,0 +1554,0 @@ inject(expression, values); |
{ | ||
"name": "code-red", | ||
"description": "code-red", | ||
"version": "0.0.16", | ||
"version": "0.0.17", | ||
"repository": "Rich-Harris/code-red", | ||
@@ -6,0 +6,0 @@ "main": "dist/code-red.js", |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
71347
2583
0