New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

es3-safe-recast

Package Overview
Dependencies
Maintainers
1
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

es3-safe-recast - npm Package Compare versions

Comparing version 0.0.5 to 0.0.6

.jshintrc

74

index.js

@@ -0,1 +1,3 @@

"use strict";
var recast = require('recast');

@@ -8,10 +10,70 @@

// http://www.ecma-international.org/publications/files/ECMA-ST-ARCH/ECMA-262,%203rd%20edition,%20December%201999.pdf
var identifierToLiteral = {
// Keyword
break: true,
case: true,
catch: true,
continue: true,
default: true,
delete: true,
do: true,
else: true,
finally: true,
catch: true,
default: true,
new: true,
throw: true,
return: true,
import: true
for: true,
function: true,
if: true,
in: true,
instanceof: true,
new: true,
return: true,
switch: true,
this: true,
throw: true,
try: true,
typeof: true,
var: true,
void: true,
while: true,
with: true,
// FutureReservedWords
abstract: true,
boolean: true,
byte: true,
char: true,
class: true,
const: true,
debugger: true,
double: true,
enum: true,
export: true,
extends: true,
final: true,
float: true,
goto: true,
implements: true,
import: true,
int: true,
interface: true,
long: true,
native: true,
package: true,
private: true,
protected: true,
public: true,
short: true,
static: true,
super: true,
synchronized: true,
throws: true,
transient: true,
volatile: true,
// NullLiteral
null: true,
// BooleanLiteral
true: true,
false: true
};

@@ -18,0 +80,0 @@

2

package.json
{
"name": "es3-safe-recast",
"version": "0.0.5",
"version": "0.0.6",
"description": "esprima/recast es3 safe compile step",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -1,8 +0,9 @@

es3-safe-recast
===============
# es3-safe-recast
Recasts all [ECMAScript 3][1] reserved words to their safe alternatives.
from:
## Before
```js
ajax('/asdf/1').catch(function() {
ajax('/asdf/1').catch(function(reason) {

@@ -14,3 +15,4 @@ }).finally(function() {

to:
## After
```js

@@ -24,22 +26,22 @@ ajax('/asdf/1')['catch'](function(reason) {

## Before
and
from:
```js
a = {
catch: function() { },
finally: function() { },
default: function() { }
object = {
catch: function() {},
finally: function() {},
default: function() {}
};
```
to:
## After
```js
a = {
'catch': function() { },
'finally': function() { },
'default': function() { }
object = {
'catch': function() {},
'finally': function() {},
'default': function() {}
};
```
[1]: http://www.ecma-international.org/publications/files/ECMA-ST-ARCH/ECMA-262,%203rd%20edition,%20December%201999.pdf

@@ -27,112 +27,85 @@ var assert = require('better-assert');

describe('catch', function() {
it('works with literal syntax', function() {
var actual = compiler.compile('var object = {\ncatch: null,\n};');
var expected = 'var object = {\n"catch": null,\n};'
function literalTestSuite(literal) {
describe(literal, function() {
it('works with literal syntax', function() {
var actual = compiler.compile('var object = {\n' + literal + ': null,\n};');
var expected = 'var object = {\n"' + literal + '": null,\n};'
astEqual(actual, expected, 'expected input.js and output.js to match');
});
astEqual(actual, expected, 'expected input.js and output.js to match');
});
it('works with member syntax', function() {
var actual = compiler.compile('object.catch(function(){\n\n});');
var expected = 'object["catch"](function(){\n\n});';
it('works with member syntax', function() {
var actual = compiler.compile('object.' + literal + '(function(){\n\n});');
var expected = 'object["' + literal + '"](function(){\n\n});';
astEqual(actual, expected, 'expected input.js and output.js to match');
astEqual(actual, expected, 'expected input.js and output.js to match');
});
});
});
}
describe('finally', function() {
it('works with literal syntax', function() {
var actual = compiler.compile('var object = {\nfinally: null,\n};');
var expected = 'var object = {\n"finally": null,\n};'
// Keyword
literalTestSuite('break');
literalTestSuite('case');
literalTestSuite('catch');
literalTestSuite('continue');
literalTestSuite('default');
literalTestSuite('delete');
literalTestSuite('do');
literalTestSuite('else');
literalTestSuite('finally');
literalTestSuite('for');
literalTestSuite('function');
literalTestSuite('if');
literalTestSuite('in');
literalTestSuite('instanceof');
literalTestSuite('new');
literalTestSuite('return');
literalTestSuite('switch');
literalTestSuite('this');
literalTestSuite('throw');
literalTestSuite('try');
literalTestSuite('typeof');
literalTestSuite('var');
literalTestSuite('void');
literalTestSuite('while');
literalTestSuite('with');
astEqual(actual, expected, 'expected input.js and output.js to match');
});
// FutureReservedWords
literalTestSuite('abstract');
literalTestSuite('boolean');
literalTestSuite('byte');
literalTestSuite('char');
literalTestSuite('class');
literalTestSuite('const');
literalTestSuite('debugger');
literalTestSuite('double');
literalTestSuite('enum');
literalTestSuite('export');
literalTestSuite('extends');
literalTestSuite('final');
literalTestSuite('float');
literalTestSuite('goto');
literalTestSuite('implements');
literalTestSuite('import');
literalTestSuite('int');
literalTestSuite('interface');
literalTestSuite('long');
literalTestSuite('native');
literalTestSuite('package');
literalTestSuite('private');
literalTestSuite('protected');
literalTestSuite('public');
literalTestSuite('short');
literalTestSuite('static');
literalTestSuite('super');
literalTestSuite('synchronized');
literalTestSuite('throws');
literalTestSuite('transient');
literalTestSuite('volatile');
it('works with member syntax', function() {
var actual = compiler.compile('object.finally(function(){\n\n});');
var expected = 'object["finally"](function(){\n\n});';
// NullLiteral
literalTestSuite('null');
astEqual(actual, expected, 'expected input.js and output.js to match');
});
});
describe('default', function() {
it('works with literal syntax', function() {
var actual = compiler.compile('var object = {\ndefault: null,\n};');
var expected = 'var object = {\n"default": null,\n};'
astEqual(actual, expected, 'expected input.js and output.js to match');
});
it('works with member syntax', function() {
var actual = compiler.compile('object.default(function(){\n\n});');
var expected = 'object["default"](function(){\n\n});';
astEqual(actual, expected, 'expected input.js and output.js to match');
});
});
describe('new', function() {
it('works with literal syntax', function() {
var actual = compiler.compile('var object = {\nnew: null,\n};');
var expected = 'var object = {\n"new": null,\n};'
astEqual(actual, expected, 'expected input.js and output.js to match');
});
it('works with member syntax', function() {
var actual = compiler.compile('object.new(function(){\n\n});');
var expected = 'object["new"](function(){\n\n});';
astEqual(actual, expected, 'expected input.js and output.js to match');
});
});
describe('throw', function() {
it('works with literal syntax', function() {
var actual = compiler.compile('var object = {\nthrow: null,\n};');
var expected = 'var object = {\n"throw": null,\n};'
astEqual(actual, expected, 'expected input.js and output.js to match');
});
it('works with member syntax', function() {
var actual = compiler.compile('object.throw(function(){\n\n});');
var expected = 'object["throw"](function(){\n\n});';
astEqual(actual, expected, 'expected input.js and output.js to match');
});
});
describe('return', function() {
it('works with literal syntax', function() {
var actual = compiler.compile('var object = {\nreturn: null,\n};');
var expected = 'var object = {\n"return": null,\n};'
astEqual(actual, expected, 'expected input.js and output.js to match');
});
it('works with member syntax', function() {
var actual = compiler.compile('object.return(function(){\n\n});');
var expected = 'object["return"](function(){\n\n});';
astEqual(actual, expected, 'expected input.js and output.js to match');
});
});
describe('import', function() {
it('works with literal syntax', function() {
var actual = compiler.compile('var object = {\nimport: null,\n};');
var expected = 'var object = {\n"import": null,\n};'
astEqual(actual, expected, 'expected input.js and output.js to match');
});
it('works with member syntax', function() {
var actual = compiler.compile('object.import(function(){\n\n});');
var expected = 'object["import"](function(){\n\n});';
astEqual(actual, expected, 'expected input.js and output.js to match');
});
});
// BooleanLiteral
literalTestSuite('true');
literalTestSuite('false');
var object = {
break: null,
case: null,
catch: null,
continue: null,
default: null,
delete: null,
do: null,
else: null,
finally: null,
catch: null,
default: null,
new: null,
throw: null,
return: null,
import: null
for: null,
function: null,
if: null,
in: null,
instanceof: null,
new: null,
return: null,
switch: null,
this: null,
throw: null,
try: null,
typeof: null,
var: null,
void: null,
while: null,
with: null,
abstract: null,
boolean: null,
byte: null,
char: null,
class: null,
const: null,
debugger: null,
double: null,
enum: null,
export: null,
extends: null,
final: null,
float: null,
goto: null,
implements: null,
import: null,
int: null,
interface: null,
long: null,
native: null,
package: null,
private: null,
protected: null,
public: null,
short: null,
static: null,
super: null,
synchronized: null,
throws: null,
transient: null,
volatile: null,
null: null,
true: null,
false: null
};
var object = {
"break": null,
"case": null,
"catch": null,
"continue": null,
"default": null,
"delete": null,
"do": null,
"else": null,
"finally": null,
"catch": null,
"default": null,
"new": null,
"throw": null,
"return": null,
"import": null
"for": null,
"function": null,
"if": null,
"in": null,
"instanceof": null,
"new": null,
"return": null,
"switch": null,
"this": null,
"throw": null,
"try": null,
"typeof": null,
"var": null,
"void": null,
"while": null,
"with": null,
"abstract": null,
"boolean": null,
"byte": null,
"char": null,
"class": null,
"const": null,
"debugger": null,
"double": null,
"enum": null,
"export": null,
"extends": null,
"final": null,
"float": null,
"goto": null,
"implements": null,
"import": null,
"int": null,
"interface": null,
"long": null,
"native": null,
"package": null,
"private": null,
"protected": null,
"public": null,
"short": null,
"static": null,
"super": null,
"synchronized": null,
"throws": null,
"transient": null,
"volatile": null,
"null": null,
"true": null,
"false": null
};

@@ -1,15 +0,119 @@

object.finally(function(){
object.break(function() {
}).catch(function(reason) {
throw reason;
}).default(function(){
}).case(function() {
}).new(function(){
}).catch(function() {
}).throw(function() {
}).continue(function() {
}).default(function() {
}).delete(function() {
}).do(function() {
}).else(function() {
}).finally(function() {
}).for(function() {
}).function(function() {
}).if(function() {
}).in(function() {
}).instanceof(function() {
}).new(function() {
}).return(function() {
}).switch(function() {
}).this(function() {
}).throw(function() {
}).try(function() {
}).typeof(function() {
}).var(function() {
}).void(function() {
}).while(function() {
}).with(function() {
}).abstract(function() {
}).boolean(function() {
}).byte(function() {
}).char(function() {
}).class(function() {
}).const(function() {
}).debugger(function() {
}).double(function() {
}).enum(function() {
}).export(function() {
}).extends(function() {
}).final(function() {
}).float(function() {
}).goto(function() {
}).implements(function() {
}).import(function() {
}).int(function() {
}).interface(function() {
}).long(function() {
}).native(function() {
}).package(function() {
}).private(function() {
}).protected(function() {
}).public(function() {
}).short(function() {
}).static(function() {
}).super(function() {
}).synchronized(function() {
}).throws(function() {
}).transient(function() {
}).volatile(function() {
}).null(function() {
}).true(function() {
}).false(function() {
});

@@ -1,15 +0,119 @@

object["finally"](function(){
object["break"](function() {
})["catch"](function(reason) {
throw reason;
})["default"](function(){
})["case"](function() {
})["new"](function(){
})["catch"](function() {
})["throw"](function() {
})["continue"](function() {
})["default"](function() {
})["delete"](function() {
})["do"](function() {
})["else"](function() {
})["finally"](function() {
})["for"](function() {
})["function"](function() {
})["if"](function() {
})["in"](function() {
})["instanceof"](function() {
})["new"](function() {
})["return"](function() {
})["switch"](function() {
})["this"](function() {
})["throw"](function() {
})["try"](function() {
})["typeof"](function() {
})["var"](function() {
})["void"](function() {
})["while"](function() {
})["with"](function() {
})["abstract"](function() {
})["boolean"](function() {
})["byte"](function() {
})["char"](function() {
})["class"](function() {
})["const"](function() {
})["debugger"](function() {
})["double"](function() {
})["enum"](function() {
})["export"](function() {
})["extends"](function() {
})["final"](function() {
})["float"](function() {
})["goto"](function() {
})["implements"](function() {
})["import"](function() {
})["int"](function() {
})["interface"](function() {
})["long"](function() {
})["native"](function() {
})["package"](function() {
})["private"](function() {
})["protected"](function() {
})["public"](function() {
})["short"](function() {
})["static"](function() {
})["super"](function() {
})["synchronized"](function() {
})["throws"](function() {
})["transient"](function() {
})["volatile"](function() {
})["null"](function() {
})["true"](function() {
})["false"](function() {
});
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