-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit f0514a2
Showing
10 changed files
with
356 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# http:https://EditorConfig.org | ||
|
||
# is this the topmost EditorConfig file? | ||
root = true | ||
|
||
[*] | ||
charset = utf-8 | ||
end_of_line = lf | ||
insert_final_newline = true | ||
trim_trailing_whitespaces = true | ||
|
||
[*.js] | ||
indent_size = 4 | ||
indent_style = space | ||
max_line_length = 80 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# Logs | ||
logs | ||
*.log | ||
|
||
# Runtime data | ||
pids | ||
*.pid | ||
*.seed | ||
|
||
# Directory for instrumented libs generated by jscoverage/JSCover | ||
lib-cov | ||
|
||
# Coverage directory used by tools like istanbul | ||
coverage | ||
|
||
# Grunt intermediate storage (http:https://gruntjs.com/creating-plugins#storing-task-files) | ||
.grunt | ||
|
||
# node-waf configuration | ||
.lock-wscript | ||
|
||
# Compiled binary addons (http:https://nodejs.org/api/addons.html) | ||
build/Release | ||
|
||
# Dependency directory | ||
# https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git- | ||
node_modules | ||
|
||
# Debug log from npm | ||
npm-debug.log | ||
|
||
# Custom | ||
|
||
dev/ | ||
dist/ | ||
target/ | ||
temp.* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
sudo: false | ||
language: node_js | ||
node_js: | ||
- '0.10' | ||
- '0.12' | ||
- '4' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
'use strict'; | ||
|
||
module.exports = function (grunt) { | ||
require('load-grunt-tasks')(grunt); | ||
|
||
grunt.initConfig({ | ||
babel: { | ||
options: { | ||
sourceMaps: 'inline', | ||
nonStandard: false, | ||
optional: [ 'strict' ], | ||
stage: 0, | ||
}, | ||
src: { | ||
expand: true, | ||
src: 'src/**/*.js', | ||
dest: 'target', | ||
}, | ||
test: { | ||
options: { | ||
plugins: [ 'babel-plugin-espower' ], | ||
}, | ||
expand: true, | ||
src: 'test/src/**/*.js', | ||
dest: 'target', | ||
} | ||
}, | ||
clean: [ 'target' ], | ||
mochaTest: { | ||
src: 'target/test/src/**/*.js' | ||
} | ||
}); | ||
|
||
grunt.registerTask('compile:src', [ 'babel:src' ]); | ||
grunt.registerTask('compile:test', [ 'babel:test' ]); | ||
grunt.registerTask('compile', [ 'compile:src', 'compile:test' ]); | ||
grunt.registerTask('test', [ 'compile', 'mochaTest' ]); | ||
grunt.registerTask('default', [ 'test' ]); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
# babel-plugin-source-map-support | ||
|
||
[![npm status](http:https://img.shields.io/npm/v/babel-plugin-source-map-support.svg)](https://www.npmjs.org/package/babel-plugin-source-map-support) | ||
[![build status](https://secure.travis-ci.org/chocolateboy/babel-plugin-source-map-support.svg)](http:https://travis-ci.org/chocolateboy/babel-plugin-source-map-support) | ||
|
||
A babel plugin which automatically enables source-map support for v8 stack traces. | ||
|
||
- [INSTALL](#install) | ||
- [SYNOPSIS](#synopsis) | ||
- [DESCRIPTION](#description) | ||
- [SEE ALSO](#see-also) | ||
- [VERSION](#version) | ||
- [AUTHOR](#author) | ||
- [COPYRIGHT AND LICENSE](#copyright-and-license) | ||
|
||
## INSTALL | ||
|
||
npm install babel-plugin-source-map-support | ||
|
||
## SYNOPSIS | ||
|
||
`$ cat test.js` | ||
|
||
```javascript | ||
|
||
import foo from 'foo'; | ||
import bar from 'bar'; | ||
|
||
test(); | ||
``` | ||
|
||
`$ babel test.js` | ||
|
||
```javascript | ||
'use strict'; | ||
|
||
var foo = require('foo'); | ||
var bar = require('bar'); | ||
|
||
test(); | ||
``` | ||
|
||
`$ babel --plugins source-map-support test.js` | ||
|
||
```javascript | ||
'use strict'; | ||
|
||
require('source-map-support/register'); | ||
|
||
var foo = require('foo'); | ||
var bar = require('bar'); | ||
|
||
test(); | ||
``` | ||
|
||
## DESCRIPTION | ||
|
||
This is a [Babel](https://www.npmjs.com/package/babel) [plugin](https://babeljs.io/docs/advanced/plugins/) | ||
which prepends a statement equivalent to the following to source files: | ||
|
||
```javascript | ||
require('source-map-support/register'); | ||
``` | ||
|
||
Note: this module doesn't install the [source-map-support](https://www.npmjs.com/package/source-map-support) | ||
module. That should be installed separately: | ||
|
||
npm install source-map-support --save | ||
|
||
## SEE ALSO | ||
|
||
* [babel](https://www.npmjs.com/package/babel) | ||
* [source-map-support](https://www.npmjs.com/package/source-map-support) | ||
|
||
## VERSION | ||
|
||
0.0.1 | ||
|
||
## AUTHOR | ||
|
||
[chocolateboy](mailto:[email protected]) | ||
|
||
## COPYRIGHT AND LICENSE | ||
|
||
Copyright © 2015 by chocolateboy | ||
|
||
This module is free software; you can redistribute it and/or modify it under the | ||
terms of the [Artistic License 2.0](http:https://www.opensource.org/licenses/artistic-license-2.0.php). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
{ | ||
"name": "babel-plugin-source-map-support", | ||
"version": "0.0.1", | ||
"description": "A babel plugin which automatically enables source-map support for v8 stack traces.", | ||
"repository": "chocolateboy/babel-plugin-source-map-support", | ||
"license": "Artistic-2.0", | ||
"main": "target/src/plugin.js", | ||
"files": [ | ||
"package.json", | ||
"CHANGELOG.md", | ||
"README.md", | ||
"target/src/plugin.js" | ||
], | ||
"dependencies": { | ||
"babel-runtime": "^5.6.17", | ||
"source-map-support": "^0.3.2" | ||
}, | ||
"devDependencies": { | ||
"babel-core": "^5.8.24", | ||
"babel-plugin-espower": "^1.0.0", | ||
"espurify": "^1.3.0", | ||
"grunt": "^0.4.5", | ||
"grunt-babel": "^5.0.1", | ||
"grunt-cli": "^0.1.13", | ||
"grunt-contrib-clean": "^0.6.0", | ||
"grunt-mocha-test": "^0.12.7", | ||
"load-grunt-tasks": "^3.2.0", | ||
"mocha": "^2.1.0", | ||
"power-assert": "^1.0.0", | ||
"rootrequire": "^1.0.0" | ||
}, | ||
"scripts": { | ||
"test": "grunt test" | ||
}, | ||
"keywords": [ | ||
"babel-plugin", | ||
"source-map", | ||
"sourcemap", | ||
"source-maps", | ||
"sourcemaps" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import 'source-map-support/register'; | ||
|
||
/* | ||
* return the AST for this statement: | ||
* | ||
* _sourceMapSupportRegister.install({ handleUncaughtException: true }) | ||
*/ | ||
function handleUncaughtExceptionNode(t, id) { | ||
return t.expressionStatement( | ||
t.callExpression( | ||
t.memberExpression( | ||
id, | ||
t.identifier('install') | ||
), [ | ||
t.objectExpression([ | ||
t.property( | ||
'init', | ||
t.identifier('handleUncaughtException'), | ||
t.literal(true) | ||
) | ||
]) | ||
] | ||
) | ||
); | ||
} | ||
|
||
export default function ({ Plugin, types: t }) { | ||
return new Plugin('source-map-support', { | ||
visitor: { | ||
Program (node, parent, scope, file) { | ||
let id = file.addImport( | ||
'source-map-support/register', | ||
null, | ||
'absolute' | ||
); | ||
|
||
// TODO when babel adds support for plugin options | ||
// https://github.com/babel/babel/issues/1833 | ||
// | ||
// let ast = handleUncaughtExceptionNode(t, id); | ||
// this.unshiftContainer('body', ast); | ||
} | ||
} | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import foo from 'foo'; | ||
import bar from 'bar'; | ||
|
||
test(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
{ | ||
"body": [ | ||
{ | ||
"expression": { | ||
"type": "Literal", | ||
"value": "use strict" | ||
}, | ||
"type": "ExpressionStatement" | ||
}, | ||
{ | ||
"source": { | ||
"type": "Literal", | ||
"value": "source-map-support/register" | ||
}, | ||
"specifiers": [], | ||
"type": "ImportDeclaration" | ||
}, | ||
{ | ||
"source": { | ||
"type": "Literal", | ||
"value": "foo" | ||
}, | ||
"specifiers": [], | ||
"type": "ImportDeclaration" | ||
}, | ||
{ | ||
"source": { | ||
"type": "Literal", | ||
"value": "bar" | ||
}, | ||
"specifiers": [], | ||
"type": "ImportDeclaration" | ||
}, | ||
{ | ||
"expression": { | ||
"arguments": [], | ||
"callee": { | ||
"name": "test", | ||
"type": "Identifier" | ||
}, | ||
"type": "CallExpression" | ||
}, | ||
"type": "ExpressionStatement" | ||
} | ||
], | ||
"sourceType": "module", | ||
"type": "Program" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import 'source-map-support/register'; | ||
import assert from 'power-assert'; | ||
import * as babel from 'babel-core'; | ||
import espurify from 'espurify'; | ||
import Fs from 'fs'; | ||
import root from 'rootrequire'; | ||
|
||
function dump ({ code, ast }) { | ||
console.log(code); | ||
console.log(require('util').inspect(espurify(ast.program), { depth: null })); | ||
} | ||
|
||
let pluginPath = `${root}/target/src/plugin.js`; | ||
|
||
describe('plugin', () => { | ||
it('prepends a require', () => { | ||
let fixture = `${root}/test/fixtures/actual.js`; | ||
let output = babel.transformFileSync(fixture, { | ||
optional: [ 'runtime', 'strict' ], | ||
plugins: [ pluginPath ], | ||
blacklist: [ 'es6.modules' ], | ||
}); | ||
|
||
// dump(output); | ||
|
||
let { inspect } = require('util'); | ||
let got = espurify(output.ast.program); | ||
let want = require(`${root}/test/fixtures/expected.json`); | ||
|
||
assert.deepEqual(got, want); | ||
}); | ||
}); |