Skip to content

Commit

Permalink
initial package with working example
Browse files Browse the repository at this point in the history
  • Loading branch information
thlorenz committed Mar 21, 2013
1 parent db4907a commit dec2b46
Show file tree
Hide file tree
Showing 4 changed files with 115 additions and 0 deletions.
15 changes: 15 additions & 0 deletions .gitignore
@@ -0,0 +1,15 @@
lib-cov
*.seed
*.log
*.csv
*.dat
*.out
*.pid
*.gz

pids
logs
results

npm-debug.log
node_modules
23 changes: 23 additions & 0 deletions LICENSE
@@ -0,0 +1,23 @@
Copyright 2013 Thorsten Lorenz.
All rights reserved.

Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without
restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following
conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
39 changes: 39 additions & 0 deletions index.js
@@ -0,0 +1,39 @@
'use strict';
var traceur = require('traceur/src/node/traceur');
var convert = require('convert-source-map');

var SourceMapGenerator = traceur.outputgeneration.SourceMapGenerator;
var TreeWriter = traceur.outputgeneration.TreeWriter;

function parse(name, source, errorReporter) {
var sourceFile = new traceur.syntax.SourceFile(name, source);
var parser = new traceur.syntax.Parser(errorReporter, sourceFile);
return parser.parseProgram();
}

function compile(filename, src, stderr) {
stderr = stderr || process.stderr;
var errorReporter = {
reportError: function(position, message) {
stderr.write('file: ' + filename + ' --- ' + message + ', ' + position + '\n');
}
};

var tree = parse(filename, src);

var generator = new SourceMapGenerator({ file: filename });
var options = { sourceMapGenerator: generator, showLineNumbers: false };

var compiledSrc = TreeWriter.write(tree, options);
var comment = convert
.fromJSON(options.sourceMap)
.setProperty('sourcesContent', compiledSrc)
.toComment();

return compiledSrc + '\n' + comment;
}


var src = 'function foo() { return 5; }\nvar \nf\n=\n5\n;\n';
var filename = 'sourceMapThis.js';
compile(src, filename);
38 changes: 38 additions & 0 deletions package.json
@@ -0,0 +1,38 @@
{
"name": "traceurify",
"version": "0.0.0",
"description": "browserify v2 transform to compile JavaScript.next (ES6) to JavaScript on the fly.",
"main": "traceurify.js",
"scripts": {
"test": "node-trap test/*.js"
},
"repository": {
"type": "git",
"url": "git://github.com/thlorenz/traceurify.git"
},
"homepage": "https://github.com/thlorenz/traceurify",
"dependencies": {
"convert-source-map": "~0.2.5",
"traceur": "0.0.1"
},
"devDependencies": {},
"keywords": [
"traceur",
"JavaScript.next",
"ES6",
"browserify",
"v2",
"js",
"plugin",
"transform"
],
"author": {
"name": "Thorsten Lorenz",
"email": "thlorenz@gmx.de",
"url": "http://thlorenz.com"
},
"license": "MIT",
"engine": {
"node": ">=0.6"
}
}

0 comments on commit dec2b46

Please sign in to comment.