Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Single character segment compatibility (needed for traceur) #14

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 13 additions & 8 deletions dist/sorcery.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ var SOURCEMAP_COMMENT = new RegExp('\n*(?:' + ('\\/\\/[@#]\\s*' + SOURCEMAPPING_
'\\/\\*#?\\s*' + SOURCEMAPPING_URL + '=([^\'"]+)\\s\\*\\/)') + // css
'\\s*$', 'g');

function slash(path) {
if (typeof path === 'string') return path.replace(/\\/g, '/');
return path;
}


/**
* Encodes a string as base64
Expand Down Expand Up @@ -258,7 +263,7 @@ var Chain = (function () {
return new SourceMap({
file: path.basename(this.node.file),
sources: allSources.map(function (source) {
return path.relative(options.base || path.dirname(_this.node.file), source);
return slash(path.relative(options.base || path.dirname(_this.node.file), source));
}),
sourcesContent: allSources.map(function (source) {
return includeContent ? _this.sourcesContentByPath[source] : null;
Expand Down Expand Up @@ -664,10 +669,10 @@ var Node = (function () {
if (generatedCodeColumn === columnIndex) {
if (segments[i].length < 4) return null;

var _sourceFileIndex = segments[i][1];
var _sourceCodeLine = segments[i][2];
var sourceCodeColumn = segments[i][3];
var _nameIndex = segments[i][4];
var _sourceFileIndex = segments[i][1] || 0;
var _sourceCodeLine = segments[i][2] || 0;
var sourceCodeColumn = segments[i][3] || 0;
var _nameIndex = segments[i][4] || 0;

var _parent = this.sources[_sourceFileIndex];
return _parent.trace(_sourceCodeLine, sourceCodeColumn, this.map.names[_nameIndex] || name);
Expand All @@ -676,9 +681,9 @@ var Node = (function () {
}

// fall back to a line mapping
var sourceFileIndex = segments[0][1];
var sourceCodeLine = segments[0][2];
var nameIndex = segments[0][4];
var sourceFileIndex = segments[0][1] || 0;
var sourceCodeLine = segments[0][2] || 0;
var nameIndex = segments[0][4] || 0;

var parent = this.sources[sourceFileIndex];
return parent.trace(sourceCodeLine, null, this.map.names[nameIndex] || name);
Expand Down
14 changes: 7 additions & 7 deletions src/Node.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,10 +133,10 @@ export default class Node {
if ( generatedCodeColumn === columnIndex ) {
if ( segments[i].length < 4 ) return null;

let sourceFileIndex = segments[i][1];
let sourceCodeLine = segments[i][2];
let sourceCodeColumn = segments[i][3];
let nameIndex = segments[i][4];
let sourceFileIndex = segments[i][1] || 0;
let sourceCodeLine = segments[i][2] || 0;
let sourceCodeColumn = segments[i][3] || 0;
let nameIndex = segments[i][4] || 0;

let parent = this.sources[ sourceFileIndex ];
return parent.trace( sourceCodeLine, sourceCodeColumn, this.map.names[ nameIndex ] || name );
Expand All @@ -145,9 +145,9 @@ export default class Node {
}

// fall back to a line mapping
let sourceFileIndex = segments[0][1];
let sourceCodeLine = segments[0][2];
let nameIndex = segments[0][4];
let sourceFileIndex = segments[0][1] || 0;
let sourceCodeLine = segments[0][2] || 0;
let nameIndex = segments[0][4] || 0;

let parent = this.sources[ sourceFileIndex ];
return parent.trace( sourceCodeLine, null, this.map.names[ nameIndex ] || name );
Expand Down