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

currentCallback is not a function #338

Closed
yuzhouu opened this issue May 14, 2018 · 5 comments
Closed

currentCallback is not a function #338

yuzhouu opened this issue May 14, 2018 · 5 comments

Comments

@yuzhouu
Copy link

yuzhouu commented May 14, 2018

os: win10
node: v8.5.0
source-map: 0.7.2

the below function will run into error currentCallback is not a function

function mergeSourcemap(
  sourceMapConsumer_1,
  sourceMapConsumer_2
) {
    sourceMapConsumer_2.eachMapping((mappingItem) => {
    const { source, column, line } = sourceMapConsumer_1.originalPositionFor({
      column: m.originalColumn,
      line: m.originalLine,
    });
  });
}

error stack:

TypeError: currentCallback is not a function
    at mapping_callback (D:\Workspace\js\sourcemap-composer\node_modules\source-map\lib\wasm.js:64:13)
    at <WASM UNNAMED> (<WASM>[30]+196)
    at BasicSourceMapConsumer_eachMapping._wasm.withMappingCallback (D:\Workspace\js\sourcemap-composer\node_modules\source-map\lib\source-map-consumer.js:404:30)
    at Object.withMappingCallback (D:\Workspace\js\sourcemap-composer\node_modules\source-map\lib\wasm.js:95:11)
    at BasicSourceMapConsumer_eachMapping [as eachMapping] (D:\Workspace\js\sourcemap-composer\node_modules\source-map\lib\source-map-consumer.js:388:16)

I guess it is caused by I invoke originnalPositionFor method of consumer_1 in the eachMapping method of consumer_2.

and for your reference
  • if I hoist the sourceMapConsumer_1.originalPositionFor from the eachMapping, this will work well
  • the same code work well in the source-map@0.5.6

thank you for your glance

@mjomble
Copy link

mjomble commented May 14, 2018

I just ran into the same problem about 20 minutes after you created the issue :)

Temporary workaround that uses more memory:

const mappingItems = [];

sourceMapConsumer_2.eachMapping((mappingItem) => mappingItems.push(mappingItem));

// The consumer can be destroyed before the for loop 
sourceMapConsumer_2.destroy();

for (const mappingItem of mappingItems) {
  const { source, column, line } = sourceMapConsumer_1.originalPositionFor({
    column: mappingItem.originalColumn,
    line: mappingItem.originalLine,
  });
  ...
}

sourceMapConsumer_1.destroy();

@yuzhouu
Copy link
Author

yuzhouu commented May 15, 2018

@mjomble yes I do the same thing to work around, as mentioned in reference 1, It dit work.

Wish mainteners have more gentler solution.

@fitzgen
Copy link
Contributor

fitzgen commented May 15, 2018

Thanks for filing an issue.

I think this is a dupe of #330 and #319 -- can you reproduce on master?

@yuzhouu
Copy link
Author

yuzhouu commented May 16, 2018

@fitzgen great job, the master branch fix the issue, Looking forward to the release of the next version

@yuzhouu yuzhouu closed this as completed May 16, 2018
@fitzgen
Copy link
Contributor

fitzgen commented May 16, 2018

Published 0.7.3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants