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
coocooooo opened this issue May 14, 2018 · 5 comments

Comments

@coocooooo
Copy link

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

This comment has been minimized.

Copy link

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();
@coocooooo

This comment has been minimized.

Copy link
Author

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

This comment has been minimized.

Copy link
Member

commented May 15, 2018

Thanks for filing an issue.

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

@coocooooo

This comment has been minimized.

Copy link
Author

commented May 16, 2018

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

@coocooooo coocooooo closed this May 16, 2018
@fitzgen

This comment has been minimized.

Copy link
Member

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
Projects
None yet
3 participants
You can’t perform that action at this time.