Socket
Socket
Sign inDemoInstall

es6-module-crosspiler

Package Overview
Dependencies
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

es6-module-crosspiler - npm Package Compare versions

Comparing version 0.2.4 to 1.0.0

7

lib/exports.js
var memo = require('memorizer')
var recast = require('recast')
var assert = require('assert')

@@ -46,3 +47,3 @@ var types = recast.types

var id = declaration.id.name
if (!id) throw new Error('unnamed function declaration')
assert(id, 'unnamed function declaration')
return exports.push([id, id])

@@ -60,7 +61,7 @@ }

var id = declaration.id.name
if (!id) throw new Error('unnamed class')
assert(id, 'unnamed class')
return exports.push([id, id])
}
throw new Error('wtf')
assert(false, 'an error occured. you are probably using a bad version of esprima')
}, this)

@@ -67,0 +68,0 @@

@@ -0,1 +1,2 @@

module.exports = require('./module')

@@ -2,0 +3,0 @@ require('./imports')

var esprima = require('esprima')
var profile = require('debug')('es6-module-crosspiler:profile')
var memo = require('memorizer')
var recast = require('recast')
module.exports = Module
Module.parse = function (string, options) {
options = options || {}
options.esprima = esprima
return recast.parse(string, options)
// for ast = x.transform(ast) recast usage
Module.transform = function (ast, options) {
return new Module(ast, options).transform()
}
Module.infer = function (string, useRegExp) {
if (useRegExp) {
var isModule = /\bexport | import |/.test(string)
return {
type: isModule ? 'module' : 'commonjs',
default: isModule && /\bexport *default */.test(string),
renames: Object.create(null),
dependencies: Object.create(null),
}
}
var ast = Module.parse(string)
var mod = new Module(ast)
mod.type
mod.default
mod.imports
mod.exports
// we don't need to keep the AST in memory
mod.ast = null
return mod
// get the dependency names of a module
// to do: think of a good name for a property
// instead of a constructor method
Module.dependenciesOf = function (mod) {
// if it's an AST
if (!(mod instanceof Module)) mod = new Module(mod)
// it already has the dependencies
return mod.imports.map(toNodeSource)
.concat(mod.requires.map(toFirstArgumentValue))
}
// for ast = x.transform(ast) recast usage
Module.transform = function (ast, options) {
return new Module(ast, options).transform()
function toNodeSource(node) {
return node.source.value
}
function toFirstArgumentValue(node) {
return node.arguments[0].value
}
function Module(ast, options) {

@@ -127,18 +118,30 @@ if (!(this instanceof Module)) return new Module(ast, options)

Module.prototype.transform = function () {
profile('beginning transform')
var module = this.type === 'module'
// rewrite all the things
this.renameRequires()
if (module) this.renameImports()
profile('renamed requires')
if (module) {
this.renameImports()
profile('renamed imports')
}
// handle any require statements first
this.defaultifyRequires()
profile('defaultified requires')
if (!module) return this.ast
// handle imports, which go below exports
this.buildRequires()
profile('built requires')
this.removeImports()
profile('removed imports')
// handle exports, which go at the top
this.buildExports()
profile('built exports')
this.removeExports()
profile('removed exports')
// build the import references
this.buildReferences()
profile('built references')
return this.ast
}
{
"name": "es6-module-crosspiler",
"description": "An ES6 and CommonJS cross-compatible transpiler",
"version": "0.2.4",
"version": "1.0.0",
"author": {

@@ -14,5 +14,5 @@ "name": "Jonathan Ong",

"dependencies": {
"debug": "*",
"memorizer": "1",
"ast-util": "0",
"esprima": "*",
"recast": "0"

@@ -26,2 +26,3 @@ },

"scripts": {
"bench": "DEBUG=*:profile node benchmark/mocha.js",
"test": "mocha --reporter spec --bail test/index.js",

@@ -28,0 +29,0 @@ "test-cov": "istanbul cover node_modules/mocha/bin/_mocha -- --reporter dot test/index.js",

@@ -5,6 +5,10 @@

[![NPM version][npm-image]][npm-url]
[![build status][travis-image]][travis-url]
[![Build status][travis-image]][travis-url]
[![Test coverage][coveralls-image]][coveralls-url]
[![Dependency Status][david-image]][david-url]
[![License][license-image]][license-url]
[![Downloads][downloads-image]][downloads-url]
[![Gittip][gittip-image]][gittip-url]
ES6 module crosspiler is an ES6 module transpiler that supports both

@@ -60,3 +64,3 @@ ES6 modules as well as CommonJS modules,

## Differences between ES6-module-transpiler
## Differences between es6-module-crosspiler

@@ -100,2 +104,12 @@ This transpiler is lower-level, meaning it does not have a concept of a container or resolver.

### Convenience Methods
#### ast = Module.transform(ast, [options])
Transform a module recast-style.
#### var names = Module.dependenciesOf(ast || module)
Get all the dependency names.
### Initialization and Metadata

@@ -226,9 +240,17 @@

[npm-image]: https://img.shields.io/npm/v/es6-module-crosspiler.svg?style=flat
[npm-image]: https://img.shields.io/npm/v/es6-module-crosspiler.svg?style=flat-square
[npm-url]: https://npmjs.org/package/es6-module-crosspiler
[travis-image]: https://img.shields.io/travis/polyfills/es6-module-crosspiler.svg?style=flat
[github-tag]: http://img.shields.io/github/tag/polyfills/es6-module-crosspiler.svg?style=flat-square
[github-url]: https://github.com/polyfills/es6-module-crosspiler/tags
[travis-image]: https://img.shields.io/travis/polyfills/es6-module-crosspiler.svg?style=flat-square
[travis-url]: https://travis-ci.org/polyfills/es6-module-crosspiler
[coveralls-image]: https://img.shields.io/coveralls/polyfills/es6-module-crosspiler.svg?style=flat
[coveralls-image]: https://img.shields.io/coveralls/polyfills/es6-module-crosspiler.svg?style=flat-square
[coveralls-url]: https://coveralls.io/r/polyfills/es6-module-crosspiler?branch=master
[gittip-image]: https://img.shields.io/gittip/jonathanong.svg?style=flat
[david-image]: http://img.shields.io/david/polyfills/es6-module-crosspiler.svg?style=flat-square
[david-url]: https://david-dm.org/polyfills/es6-module-crosspiler
[license-image]: http://img.shields.io/npm/l/es6-module-crosspiler.svg?style=flat-square
[license-url]: LICENSE
[downloads-image]: http://img.shields.io/npm/dm/es6-module-crosspiler.svg?style=flat-square
[downloads-url]: https://npmjs.org/package/es6-module-crosspiler
[gittip-image]: https://img.shields.io/gittip/jonathanong.svg?style=flat-square
[gittip-url]: https://www.gittip.com/jonathanong/
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