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

es6-class

Package Overview
Dependencies
Maintainers
1
Versions
24
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

es6-class - npm Package Compare versions

Comparing version 0.2.0 to 0.3.0

CHANGELOG.md

2

bower.json
{
"name": "es6-class",
"version": "0.2.0",
"version": "0.3.0",
"homepage": "https://github.com/square/es6-class",

@@ -5,0 +5,0 @@ "authors": [

var assert = require('assert');
var parse = require('esprima').parse;
var through = require('through');
var guessTabWidth = require('./util').guessTabWidth;
var esprimaHarmony = require("esprima");

@@ -60,7 +59,8 @@ var recast = require('recast');

function addPropertyDescriptor(property, key, value) {
function addPropertyDescriptor(property, key, value, isStatic) {
if (!propertyDescriptorMap[property]) {
propertyDescriptors.push({
name: property,
descriptor: propertyDescriptorMap[property] = Object.create(DEFAULT_PROPERTY_DESCRIPTOR)
descriptor: propertyDescriptorMap[property] = Object.create(DEFAULT_PROPERTY_DESCRIPTOR),
isStatic: isStatic
});

@@ -79,2 +79,3 @@ }

var methodName = statement.key.name;
var isStatic = statement.static;

@@ -93,3 +94,4 @@ if (methodName === 'constructor') {

'value',
b.functionExpression(null, fn.params, fn.body)
b.functionExpression(null, fn.params, fn.body),
isStatic
);

@@ -191,2 +193,10 @@ }

}
var object;
if (propertyDescriptor.isStatic) {
object = node.id;
} else {
object = b.memberExpression(node.id, b.identifier('prototype'), false);
}
definitionStatements.push(b.expressionStatement(b.callExpression(

@@ -199,3 +209,3 @@ b.memberExpression(

[
b.memberExpression(node.id, b.identifier('prototype'), false),
object,
b.literal(propertyDescriptor.name),

@@ -262,3 +272,7 @@ b.objectExpression(descriptorObjectProperties)

if (classDeclaration && methodDefinition) {
// Replace `super()` with `Object.getPrototypeOf(MyClass.prototype).myMethod.call(this)`.
// Replace `super()` with `Object.getPrototypeOf(MyClass[.prototype]).myMethod.call(this)`.
var context = methodDefinition.static ?
classDeclaration.id :
b.memberExpression(classDeclaration.id, b.identifier('prototype'), false);
this.replace(b.callExpression(

@@ -273,3 +287,3 @@ b.memberExpression(

),
[b.memberExpression(classDeclaration.id, b.identifier('prototype'), false)]
[context]
),

@@ -381,4 +395,3 @@ methodDefinition.key,

var recastOptions = {
tabWidth: guessTabWidth(source),
// Use the harmony branch of Esprima that installs with regenerator
// Use the harmony branch of Esprima that installs with es6-class
// instead of the master branch that recast provides.

@@ -385,0 +398,0 @@ esprima: esprimaHarmony,

{
"name": "es6-class",
"version": "0.2.0",
"version": "0.3.0",
"description": "ES6 classes compiled to ES5.",

@@ -20,5 +20,3 @@ "main": "lib/index.js",

"devDependencies": {
"glob": "^3.2.9",
"googlediff": "^0.1.0",
"cli-color": "^0.2.3"
"example-runner": "0.1.0"
},

@@ -25,0 +23,0 @@ "scripts": {

@@ -7,126 +7,22 @@ /**

Error.stackTraceLimit = 20;
var compile = require('../lib').compile;
var fs = require('fs');
var path = require('path');
var glob = require('glob');
var RESULTS = 'test/results';
var vm = require('vm');
var assert = require('assert');
var helper = require('./test_helper');
var normalize = helper.normalize;
var compile = helper.compile;
var indent = helper.indent;
var diff = helper.diff;
var color = require('cli-color');
var header = color.bold;
/**
* Prints a line to stdout for the given test indicating that it passed.
*
* @param {string} testName
*/
function printSuccess(testName) {
console.log('✓ ' + testName);
if (!fs.existsSync(RESULTS)) {
fs.mkdirSync(RESULTS);
}
/**
* Prints a line to stdout for the given test indicating that it failed. In
* addition, prints any additional information indented one level.
*
* @param {string} testName
* @param {Array.<string>} chunks
*/
function printFailure(testName, chunks) {
console.log('✘ ' + testName);
console.log();
chunks.forEach(function(chunk) {
console.log(indent(chunk, 1));
require('example-runner').runCLI(function(source, testName, filename) {
var result = compile(source, {
includeRuntime: true,
sourceFileName: filename,
sourceMapName: filename + '.map'
});
}
/**
* Runs the test for the given source files, printing the results and calling
* the callback with the success status of the test.
*
* @param {string} basename
* @param {string} filename
* @param {function(boolean)} callback
*/
function runTest(basename, filename, callback) {
/**
* Notifies the callback that we were unsuccessful and prints the error info.
*
* @param {Error} err
* @private
*/
function error(err) {
printFailure(basename, [err.stack, '']);
callback(false);
}
fs.readFile(filename, 'utf8', function(err, source) {
if (err) { return error(err); }
try {
vm.runInNewContext(compile(source).code, { assert: assert });
printSuccess(basename);
callback(true);
} catch (ex) {
error(ex);
}
});
}
/**
* Tests the library using the given ES6 source file. Calls back with a
* success/failure status flag.
*
* @param {string} filename
* @param {function(boolean)} callback
*/
function processFile(filename, callback) {
var basename = path.basename(filename, '.js');
runTest(basename, filename, callback);
}
/**
* Runs the given test files and exits with the appropriate status code.
*
* @param {Array.<string>} filenames
*/
function run(filenames) {
var passed = [];
var failed = [];
function next() {
var filename = filenames.shift();
if (filename) {
processFile(filename, function(success) {
(success ? passed : failed).push(path.basename(filename, '.js'));
next();
});
} else {
done();
}
}
function done() {
console.log();
console.log('' + (passed.length + failed.length) + ' total, ' + passed.length + ' passed, ' + failed.length + ' failed.');
process.exit(failed.length ? 1 : 0);
}
next();
}
var files = process.argv.slice(2);
if (files.length) {
run(files);
} else {
glob(path.join(__dirname, 'examples/*.js'), function(err, files) {
if (err) { throw err; }
run(files);
});
}
fs.writeFileSync(path.join(RESULTS, testName + '.js'), result.code, 'utf8');
fs.writeFileSync(path.join(RESULTS, testName + '.js.map'), JSON.stringify(result.map), 'utf8');
return result.code;
});

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