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

Errors with usage in CRAv2 #6

Open
cpannwitz opened this issue Jun 17, 2018 · 5 comments
Open

Errors with usage in CRAv2 #6

cpannwitz opened this issue Jun 17, 2018 · 5 comments

Comments

@cpannwitz
Copy link

cpannwitz commented Jun 17, 2018

Bug

  • babel-plugin-console version: 0.2.1
  • node version: 9.5.0
  • npm (or yarn) version: yarn 1.7.0

Relevant code or config

import React, { Component } from "react";
import scope from "scope.macro";

function add100(a) {
  const oneHundred = 100;
  scope("Add 100 to another number");
  return add(a, oneHundred);
}

function add(a, b) {
  return a + b;
}

class App extends Component {
  componentDidMount = () => {
    add100(1);
  };

  render() {
    return (
      <div className="App">
      </div>
    );
  }
}

export default App;

What you did:

  1. npx create-react-app@next --scripts-version=2.0.0-next.66cc7a90
  2. yarn add babel-plugin-console & yarn add scope.macro
  3. Inserted above example code from this plugins pages in barebones CRAv2 App.js
  4. yarn start

What happened (please provide anything you think will help):

index.js:2214 ./src/App.js
Module build failed: Error: Unknown substitution "args" given
    at Array.forEach (<anonymous>)
    at Array.map (<anonymous>)
    =============
    at Array.map (<anonymous>)
    at Array.forEach (<anonymous>)

As far as I know, the upcoming Create-React-App version 2 comes with built-in support for babel-macros.
I also checked with another babel-macro plugin, which is working fine.

Edit: missed a line.

@michaelsbradleyjr
Copy link

michaelsbradleyjr commented Oct 4, 2018

I have experienced the exact same problem with scope.macro, while other macros work, e.g. it from param.macro.

@CanRau
Copy link

CanRau commented Nov 1, 2018

Get the same error message 😣

@vjpr
Copy link

vjpr commented Nov 18, 2018

Found the problem.

@mattphillips

const buildLog = template => (...args) => level => {
  if (level == 0) {
    return template('console.log(args);')({ args });
  }

  const indentation = indentWith(level, '| ', '| ');
  return template(`
    if (typeof window !== 'undefined') {
      console.log(args);
    } else {
      console.log('${indentation}', args);

    }
  `)({ args });
};

Should be:

const buildLog = template => (...args) => level => {
  if (level == 0) {
    return template('console.log(ARGS);')({ ARGS });
  }

  const indentation = indentWith(level, '| ', '| ');
  return template(`
    if (typeof window !== 'undefined') {
      console.log(ARGS);
    } else {
      console.log('${indentation}', ARGS);

    }
  `)({ ARGS });
};

There are also other usages that need changing.


Placeholders must be capitalized.

Note the lowercase placeholder in the babel template.


https://babeljs.io/docs/en/next/babel-template.html#placeholderpattern:

placeholderPattern
Type: RegExp | false Default: /^[_$A-Z0-9]+$/

A pattern to search for when looking for Identifier and StringLiteral nodes that should be considered placeholders. 'false' will disable placeholder searching entirely, leaving only the 'placeholderWhitelist' value to find placeholders.

@vjpr
Copy link

vjpr commented Nov 18, 2018

PR: #8

@cyrus-za
Copy link

Experiencing this issue with CRAv3

Using Typescript with CRA on MacOS.

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

5 participants