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

Unexpected regular expression #44

Open
alexander-akait opened this issue Feb 4, 2019 · 6 comments
Open

Unexpected regular expression #44

alexander-akait opened this issue Feb 4, 2019 · 6 comments

Comments

@alexander-akait
Copy link

Input:

const options = {
      file: 'test5.js',
      input: '/******/ function hello(a) {console.log(a)}',
      terserOptions: {
        output: {
          comments: 'all',
        },
      },
      extractComments: {
        condition: 'should be extracted',
        filename: (file) => file.replace(/(\.\w+)$/, '.license$1'),
        banner: (licenseFile) =>
          `License information can be found in ${licenseFile}`,
      },
    }

After serialize we use

const options = new Function(
      'exports',
      'require',
      'module',
      '__filename',
      '__dirname',
      `'use strict'\nreturn ${options}`
    )(exports, require, module, __filename, __dirname);

And code in Function throw SyntaxError: Unexpected regular expression

@krutzler

This comment was marked as outdated.

@alexander-akait
Copy link
Author

@krutzler no, i have problems with package and yahoo as always terribly maintenance own repos, instead of a live response, I get a robot 😞

@alexander-akait
Copy link
Author

/cc @okuryu friendly ping, we still have problem with example above

@okuryu
Copy link
Collaborator

okuryu commented Apr 17, 2019

test.js:

const serialize = require('serialize-javascript')

const options = {
      file: 'test5.js',
      input: '/******/ function hello(a) {console.log(a)}',
      terserOptions: {
        output: {
          comments: 'all',
        },
      },
      extractComments: {
        condition: 'should be extracted',
        filename: (file) => file.replace(/(\.\w+)$/, '.license$1'),
        banner: (licenseFile) =>
          `License information can be found in ${licenseFile}`,
      },
    }

console.log(serialize(options))
$ node test.js
{"file":"test5.js","input":"\u002F******\u002F function hello(a) {console.log(a)}","terserOptions":{"output":{"comments":"all"}},"extractComments":{"condition":"should be extracted","filename":(file) => file.replace(/(\.\w+)$/, '.license$1'),"banner":(licenseFile) =>
          `License information can be found in ${licenseFile}`}}

Did you mean that / should serialize to / not \u002F?

@alexander-akait
Copy link
Author

@okuryu yep, because deserialize not working in this case

@okuryu
Copy link
Collaborator

okuryu commented Apr 17, 2019

Hmm. it seems to be a bug. I'll try to fix it, but it may take some time. Your cooperation is always welcome.

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