Comparing version 0.0.4 to 0.0.5
# code-red changelog | ||
## 0.0.5 | ||
* Omit missing statements | ||
* Flatten arrays of statements | ||
## 0.0.4 | ||
@@ -4,0 +9,0 @@ |
(function (global, factory) { | ||
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('astring'), require('source-map'), require('periscopic'), require('estree-walker'), require('is-reference'), require('acorn')) : | ||
typeof define === 'function' && define.amd ? define(['exports', 'astring', 'source-map', 'periscopic', 'estree-walker', 'is-reference', 'acorn'], factory) : | ||
(factory((global.CodeRed = {}),global.astring,global.SourceMap,global.perisopic,global.estreeWalker,global.is_reference,global.acorn)); | ||
}(this, (function (exports,astring,SourceMap,perisopic,estreeWalker,is_reference,acorn) { 'use strict'; | ||
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('astring'), require('periscopic'), require('estree-walker'), require('is-reference'), require('acorn')) : | ||
typeof define === 'function' && define.amd ? define(['exports', 'astring', 'periscopic', 'estree-walker', 'is-reference', 'acorn'], factory) : | ||
(factory((global.CodeRed = {}),global.astring,global.perisopic,global.estreeWalker,global.is_reference,global.acorn)); | ||
}(this, (function (exports,astring,perisopic,estreeWalker,is_reference,acorn) { 'use strict'; | ||
@@ -36,2 +36,4 @@ is_reference = is_reference && is_reference.hasOwnProperty('default') ? is_reference['default'] : is_reference; | ||
handle( node, state) { | ||
// console.log('----> handling', JSON.stringify(node, null, ' ')); | ||
if (Array.isArray(node)) { | ||
@@ -57,3 +59,15 @@ for (let i = 0; i < node.length; i += 1) { | ||
this[node.type](node, state); | ||
try { | ||
this[node.type](node, state); | ||
} catch (err) { | ||
if (!err.depth) { | ||
console.log(`${err.message} while handling`, node); | ||
err.depth = 1; | ||
} else if (err.depth <= 3) { | ||
console.log(`${err.depth}:`, node); | ||
err.depth += 1; | ||
} | ||
throw err; | ||
} | ||
}, | ||
@@ -79,2 +93,6 @@ AwaitExpression( node, state) { | ||
Identifier( node, state) { | ||
if (!node.name) { | ||
console.log(node); | ||
} | ||
if (node.name[0] === '@') { | ||
@@ -86,2 +104,5 @@ node = { ...node, name: getName(node.name.slice(1)) }; | ||
const scope = scope_map.get(node); | ||
if (!scope) { | ||
throw new Error(`Could not find scope for node`); | ||
} | ||
const owner = scope.find_owner(node.name); | ||
@@ -107,5 +128,5 @@ | ||
const map = new SourceMap.SourceMapGenerator({ | ||
file: opts.file | ||
}); | ||
// const map = new SourceMap.SourceMapGenerator({ | ||
// file: opts.file | ||
// }); | ||
@@ -119,3 +140,3 @@ const code = astring.generate(node , { | ||
code, | ||
map | ||
map: null | ||
}; | ||
@@ -137,5 +158,28 @@ } | ||
const flatten = (array, target) => { | ||
for (let i = 0; i < array.length; i += 1) { | ||
const statement = array[i]; | ||
if (Array.isArray(statement)) { | ||
flatten(statement, target); | ||
continue; | ||
} | ||
if (statement.type === 'ExpressionStatement') { | ||
if (!statement.expression) continue; | ||
if (Array.isArray(statement.expression)) { | ||
flatten(statement.expression, target); | ||
continue; | ||
} | ||
} | ||
target.push(statement); | ||
} | ||
return target; | ||
}; | ||
const inject = (node, values) => { | ||
estreeWalker.walk(node, { | ||
enter(node, parent, key, index) { | ||
leave(node, parent, key, index) { | ||
delete node.start; | ||
@@ -159,2 +203,6 @@ delete node.end; | ||
} | ||
if (node.type === 'Program' || node.type === 'BlockStatement') { | ||
node.body = flatten(node.body, []); | ||
} | ||
} | ||
@@ -161,0 +209,0 @@ }); |
{ | ||
"name": "code-red", | ||
"description": "code-red", | ||
"version": "0.0.4", | ||
"version": "0.0.5", | ||
"repository": "Rich-Harris/code-red", | ||
@@ -6,0 +6,0 @@ "main": "dist/code-red.js", |
import * as acorn from 'acorn'; | ||
import * as SourceMap from 'source-map'; | ||
declare type PrintOptions = { | ||
@@ -9,4 +8,4 @@ file?: string; | ||
code: string; | ||
map: SourceMap.SourceMapGenerator; | ||
map: any; | ||
}; | ||
export {}; |
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
15317
397