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

Code Replace is not a function #33

Open
mascardoso opened this issue Aug 30, 2017 · 1 comment
Open

Code Replace is not a function #33

mascardoso opened this issue Aug 30, 2017 · 1 comment

Comments

@mascardoso
Copy link

I keep getting this issue after trying to use the scss comment parser:

code.replace is not a function
TypeError: code.replace is not a function
    at unifyLineEndings (http://localhost:6060/static/preview.bundle.js:52937:17)
    at CommentExtractor.extract (http://localhost:6060/static/preview.bundle.js:52974:12)
    at Parser.parse (http://localhost:6060/static/preview.bundle.js:52782:28)
    at Object.<anonymous> (http://localhost:6060/static/preview.bundle.js:52253:23)
    at __webpack_require__ (http://localhost:6060/static/preview.bundle.js:677:30)
    at fn (http://localhost:6060/static/preview.bundle.js:88:20)
    at http://localhost:6060/static/preview.bundle.js:41388:10
    at ConfigApi._renderMain (http://localhost:6060/static/preview.bundle.js:46217:20)
    at render (http://localhost:6060/static/preview.bundle.js:46243:17)
    at ConfigApi.configure (http://localhost:6060/static/preview.bundle.js:46268:9)

This is the code I currently have:

const ScssCommentParser = require('scss-comment-parser');

const annotations = {
  _: {
    alias: {
      'aliasTest': 'annotationTest'
    }
  },
  annotationTest: function ( commentLine ) {
    return 'Working';
  }
};

const parser = new ScssCommentParser( annotations );


const scss = require('../front/scss/config.scss')
const comments = parser.parse( scss )

console.log(comments);

Probably I'm doing something wrong but the scss const returns an empty object. Are u loading the scss in a different way?

Thanks

@S0AndS0
Copy link

S0AndS0 commented May 7, 2020

It seems this error is achievable by feeding non-string data as an input.

Not sure if require returns a string but I got the following to not error out by using fs.readFileSync instead...

#!/usr/bin/env node

const scss_comment_parser = require('scss-comment-parser');
const fs = require('fs');
const path = require('path');

const annotations = {
  _: {
    alias: {
      'aliasTest': 'annotationTest'
    }
  },
  annotationTest: function ( commentLine ) {
    return 'Working';
  }
};

const parser = new scss_comment_parser(annotations);
const scss_data = fs.readFileSync(path.join(__dirname, 'test-prefixes.scss'));
const parser_data = parser.parse(scss_data.toString());

console.log(parser_data);

... the magic sauce was passing the results of toString() from the read file buffer into parser.parse method.

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

No branches or pull requests

2 participants