serialize-javascript icon indicating copy to clipboard operation
serialize-javascript copied to clipboard

Unexpected regular expression

Open alexander-akait opened this issue 6 years ago • 6 comments

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

alexander-akait avatar Feb 04 '19 11:02 alexander-akait

Hello,

This employee can no longer access email on this account. Your email will not be forwarded.

If you have a sales inquiry, please contact [email protected]

If you require assistance with a legal matter, please contact [email protected]

Thank you!

krutzler avatar Feb 04 '19 11:02 krutzler

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

alexander-akait avatar Feb 04 '19 11:02 alexander-akait

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

alexander-akait avatar Apr 16 '19 12:04 alexander-akait

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?

okuryu avatar Apr 17 '19 13:04 okuryu

@okuryu yep, because deserialize not working in this case

alexander-akait avatar Apr 17 '19 14:04 alexander-akait

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

okuryu avatar Apr 17 '19 14:04 okuryu