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

hookRequire passes an object to the transformer function, not a string #153

Open
kevinkir opened this issue Mar 27, 2018 · 0 comments
Open

Comments

@kevinkir
Copy link
Contributor

kevinkir commented Mar 27, 2018

The hookRequire function in the hook.js file of istanbul-lib-hook does not behave as documented.

The JSDoc for hookRequire has

@param transformer {Function(code, filePath)} a function called with the original code and the associated path of the file from where the code was loaded. Should return the transformed code.

This also matches its type definition:

type Transformer = (code: string, filepath: string) => string;

However, what actually gets passed as the second argument to the transformer callback is an object that looks like this: { filename: '/the/file/path' }.

The problematic lines of code are

// hook.js#16
if (typeof options === 'string') {
    options = { filename: options };
}
// ...
// hook.js#29
transformed = transformer(code, options);

The options to fix this would be either:

  • update the documentation and type interface to reflect the actual behavior
  • Change hook.js#29 to transformed = transformer(code, options.filename);
kevinkir pushed a commit to kevinkir/istanbuljs that referenced this issue Mar 27, 2018
bcoe added a commit that referenced this issue Mar 31, 2018
bcoe added a commit that referenced this issue Mar 31, 2018
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

1 participant