traceur-source-maps

2018-12-07 admin

traceur-source-maps是什么

什么是traceur-source-maps,Provides source map for Node.js files when using Traceur on the fly.

traceur-source-maps使用教程帮助文档

traceur-source-maps

NPM version Build status Coveralls status Support us

When using Traceur as a command-line utility to transpile Node.js source code, it provides --source-maps option to create source map files. But when using at runtime by requiring traceur module to live-transpile files, Traceur lacks the ability to reports correct stack trace.

Here comes this module to solve that problem: it provides source map for Node.js files when using Traceur on the fly.

Installation

This module can be installed easily with npm:

$ npm install traceur-source-maps

Usage

Below is a small example to describe how to use this module.

bootstrap.js:

var traceur = require('traceur');

require('traceur-source-maps').install(traceur);

traceur.require.makeDefault(function (filePath) {
  return !~filePath.indexOf('node_modules');
});
// There is no need to pass `{ sourceMaps: true }` as options,
// source mapping is always enabled after install

require('./main');

main.js:

import { hey } from './greet';

hey();

greet.js:

export function hey() {
  hi();
}

export function hi() {
  throw new Error('Call me maybe!');
}

Run bootstrap.js using Node.js, notice the stack trace reports correct line number where the error occurred (line 6 of greet.js).

$ node bootstrap.js

/some/dir/greet.js:6
  throw new Error('Call me maybe!');

        ^
Error: Call me maybe!
    at hi (/some/dir/greet.js:6:9)
    at hey (/some/dir/greet.js:2:3)
    at Object.<anonymous> (/some/dir/main.js:3:1)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (/some/dir/node_modules/traceur-source-maps/node_modules/traceur/src/node/require.js:65:21)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Module.require (module.js:364:17)
    at require (module.js:380:17)
    at Object.<anonymous> (/some/dir/bootstrap.js:12:1)

Compatibility

  • This module conflicts with all source code which uses source-map-support module (or maybe some modules with similar features) to provide source mapping.

  • This module has been tested to run properly with Traceur version 0.0.72 (latest version at the time of writing). It could be broken in the future if Traceur introduces non backward-compatible changes. In that circumstance, feel free to create new issue or create a pull request.

Contributing

Before create a pull request, make sure that you:

To execute all tests, simply run:

$ npm test

Contributors

License

This module is released under MIT license.

本站文章除注明转载外,均为本站原创或编译。欢迎任何形式的转载,但请务必注明出处。

转载请注明:文章转载自 JavaScript中文网 [https://www.javascriptcn.com]

本文地址:https://www.javascriptcn.com/read-47498.html

文章标题:traceur-source-maps

回到顶部