Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

redeyed

Package Overview
Dependencies
Maintainers
1
Versions
20
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

redeyed - npm Package Compare versions

Comparing version 0.6.0 to 1.0.0

test/redeyed-incomplete.js

4

package.json
{
"name": "redeyed",
"version": "0.6.0",
"version": "1.0.0",
"description": "Takes JavaScript code, along with a config and returns the original code with tokens wrapped as configured.",

@@ -26,3 +26,3 @@ "author": "Thorsten Lorenz <thlorenz@gmx.de> (thlorenz.com)",

"devDependencies": {
"tap": "~0.4.8",
"tap": "~5.7.0",
"readdirp": "~0.3.3",

@@ -29,0 +29,0 @@ "cardinal": "~0.4.4"

@@ -135,2 +135,6 @@ # redeyed [![build status](https://secure.travis-ci.org/thlorenz/redeyed.png?branch=master)](http://travis-ci.org/thlorenz/redeyed)

{ // {Boolean}
// if true `result.ast` property contains the abstract syntax tree of the code
// if false (default) `result.ast` is not assigned and therefore `undefined`
buildAst: true|false
// {Boolean}
// if true `result.code` is not assigned and therefore `undefined`

@@ -137,0 +141,0 @@ // if false (default) `result.code` property contains the result of `split.join`

@@ -176,2 +176,3 @@ ;(function () {

var parser = opts.parser || esprima;
var buildAst = !!opts.buildAst;

@@ -181,5 +182,5 @@ // remove shebang

var ast = parser.parse(code, { tokens: true, comment: true, range: true, tolerant: true })
, tokens = ast.tokens
, comments = ast.comments
var ast
, tokens
, comments
, lastSplitEnd = 0

@@ -192,2 +193,24 @@ , splits = []

if (buildAst) {
ast = parser.parse(code, { tokens: true, comment: true, range: true, tolerant: true });
tokens = ast.tokens;
comments = ast.comments;
} else {
tokens = [];
comments = [];
parser.tokenize(code, { range: true, comment: true }, function (token) {
if (token.type === 'LineComment') {
token.type = 'Line';
comments.push(token)
} else if (token.type === 'BlockComment') {
token.type = 'Block';
comments.push(token)
} else {
// Optimistically upgrade 'static' to a keyword
if (token.type === 'Identifier' && token.value === 'static') token.type = 'Keyword';
tokens.push(token);
}
});
}
normalize(config);

@@ -194,0 +217,0 @@

@@ -54,2 +54,4 @@ 'use strict';

})
t.end()
})

@@ -43,2 +43,4 @@ 'use strict';

})
t.end()
})

@@ -72,2 +74,4 @@

})
t.end()
})

@@ -57,2 +57,3 @@ 'use strict';

})
t.end()
})

@@ -71,2 +71,4 @@ 'use strict';

})
t.end()
})

@@ -95,2 +97,4 @@

})
t.end()
})

@@ -144,2 +148,4 @@

})
t.end()
})

@@ -43,2 +43,4 @@ 'use strict';

})
})
t.end()
})

@@ -46,2 +46,4 @@ 'use strict';

})
t.end()
})

@@ -13,3 +13,3 @@ 'use strict';

test('redeyed result has esprima ast, tokens, comments and splits and transformed code', function (t) {
test('redeyed result does not have esprima ast by default', function (t) {
var code = '// a comment\nvar a = 3;'

@@ -24,2 +24,19 @@ , conf = { Keyword: { _default: '_:-' } }

t.type(result.ast, 'undefined', 'ast')
t.deepEquals(result.tokens, tokens, 'tokens')
t.deepEquals(result.comments, comments, 'comments')
t.notEquals(result.code, undefined, 'code')
t.end()
});
test('redeyed result has esprima ast, tokens, comments and splits and transformed code', function (t) {
var code = '// a comment\nvar a = 3;'
, conf = { Keyword: { _default: '_:-' } }
, ast = esprima.parse(code, { tokens: true, comment: true, range: true, tolerant: true })
, tokens = ast.tokens
, comments = ast.comments
, result = redeyed(code, conf, { buildAst: true } )
console.log(ast)

@@ -42,3 +59,3 @@ t.deepEquals(result.ast, ast, 'ast')

, result = redeyed(code, conf, { nojoin: true })
, result = redeyed(code, conf, { nojoin: true, buildAst: true })

@@ -45,0 +62,0 @@ t.deepEquals(result.ast, ast, 'ast')

@@ -16,15 +16,36 @@ 'use strict';

var invalidTapFiles = [
'async-map-ordered.js'
, 'prof.js'
'services/localGit.js'
, 'lib/handlebars/runtime.js'
, 'handlebars/lib/precompiler.js'
, 'handlebars/compiler/javascript-compiler.js'
, 'slide/lib/async-map-ordered.js'
, 'resolve/test/precedence/'
, 'is-relative/index.js'
, 'is-buffer/test/'
, 'lodash/utility/'
]
function shouldProcess (path) {
var include = true
invalidTapFiles.every(function (entry) {
return include = (path.indexOf(entry) < 0)
});
return include
}
readdirp({ root: tapdir, fileFilter: '*.js' })
.on('data', function (entry) {
if (~invalidTapFiles.indexOf(entry.name)) return
if (!shouldProcess(entry.fullPath)) {
return
}
var code = fs.readFileSync(entry.fullPath, 'utf-8')
, result = redeyed(code, { Keyword: { 'var': '+:-' } }).code
, resultAst = redeyed(code, { Keyword: { 'var': '+:-' } }, { buildAst: true }).code
, resultTokenize = redeyed(code, { Keyword: { 'var': '+:-' } }, { buildAst: false }).code
t.assert(~result.indexOf('+var-') || !(~result.indexOf('var ')), 'redeyed ' + entry.path)
t.assert(~resultAst.indexOf('+var-') || !(~resultAst.indexOf('var ')), 'redeyed ' + entry.path)
t.assert(~resultTokenize.indexOf('+var-') || !(~resultTokenize.indexOf('var ')), 'redeyed ' + entry.path)
})

@@ -38,7 +59,9 @@ .on('end', t.end.bind(t))

.on('data', function (entry) {
var code = fs.readFileSync(entry.fullPath, 'utf-8')
, result = redeyed(code, { Keyword: { 'var': '+:-' } }).code
, resultAst = redeyed(code, { Keyword: { 'var': '+:-' } }, { buildAst: true }).code
, resultTokenize = redeyed(code, { Keyword: { 'var': '+:-' } }, { buildAst: false }).code
t.assert(~result.indexOf('+var-') || !(~result.indexOf('var ')), 'redeyed ' + entry.path)
t.assert(~resultAst.indexOf('+var-') || !(~resultAst.indexOf('var ')), 'redeyed ' + entry.path)
t.assert(~resultTokenize.indexOf('+var-') || !(~resultTokenize.indexOf('var ')), 'redeyed ' + entry.path)
})

@@ -52,3 +75,3 @@ .on('end', t.end.bind(t))

.on('data', function (entry) {
var code = fs.readFileSync(entry.fullPath, 'utf-8')

@@ -55,0 +78,0 @@ , result = redeyed(code, { Keyword: { 'var': '+:-' } }).code

@@ -55,2 +55,4 @@ 'use strict';

})
t.end()
})

@@ -122,2 +124,3 @@

run(t, { 'Boolean': { 'true': undefined, 'false': undefined, _default: '+:-' } }, 'return +true- || +false-;', 'return true || false;')
t.end()
})

@@ -124,0 +127,0 @@

@@ -75,2 +75,4 @@ 'use strict';

})
t.end()
})

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc