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

Allow use of let and const in p5js-mode #20

Closed
schellenberg opened this issue Jun 5, 2018 · 4 comments
Closed

Allow use of let and const in p5js-mode #20

schellenberg opened this issue Jun 5, 2018 · 4 comments

Comments

@schellenberg
Copy link

As I was investigating using p5js-mode, I noticed that I could not use let or const without obtaining an error after saving the code. For example, this works fine:

function setup() {
  createCanvas(1000, 700);
}

function draw() {
  var someColor = random(255);
  fill(someColor, random(255), random(255), random(255));
  rect(random(width), random(height), 30, 30);
}

But if the var is replaced by let, like this:

function setup() {
  createCanvas(1000, 700);
}

function draw() {
  var someColor = random(255);
  fill(someColor, random(255), random(255), random(255));
  rect(random(width), random(height), 30, 30);
}

then an error of SyntaxError: Expected ; but found someColor is thrown.

This seems to be the same problem that occurred in #18. As I stated there, I poked around the source of p5js-mode, and I'm wondering if the issue lies in the public HtmlTokenMarker(boolean js) function in the HTMLTokenMarker.java file. I can see var in there, but the more recent let and const ES6 style variable declarations are not. Perhaps it is as simple as adding those?

@benfry
Copy link
Contributor

benfry commented Jul 24, 2018

I think the simple syntax checker that it uses just isn't up to date with let and const. Will take a look next time I have the chance to work on this.

@MagusDrk
Copy link

Hello everyone.

I'm facing exactly the same problem. I've created a simple sketch to draw some characters randonmly in the screen and it wors fine, but when i save the sketch, the same error appears. For me is not a solution to use var instead of let, because I get the same error.

the only wird thing is the appearence of a new js file wich looks like a temp file, in my case: p5js-temp-cartografia_del_fracaso7261114787448830096.js. I've deleted it, but nothing changes and later, it reappears.

I want to share my sketch with you to analize the error and get a fix.

code:

var letters = [];
var content;

function preload() {
  content = loadStrings('/assets/text.txt');
}

function setup() {
  createCanvas(300, 200);
  for (var i = 0; i < content.length; i++) {
    var s = content[i];
    for (var j = 0; j < s.length; j++) {
      letters.push(new Letter(s.charAt(j), random(width), random(height)));
    }
  }
  console.log(letters.length);
}

function draw() {
  background(255);
  for (var i = 0; i < letters.length; i++) {
    letters[i].show();
  }
}

class  Letter {

  constructor(l, x, y, h = 12) {
    this.l= l; 
    this.x= x; 
    this.y= y; 
    this.h= h;
  }

  show() {
    fill(0);
    textAlign(CENTER, CENTER);
    textSize(this.h);
    this.w = textWidth(this.l);
    text(this.l, this.x, this.y);
  }
}

index.html

<html>
<head>
  <meta charset="UTF-8">

  <!-- PLEASE NO CHANGES BELOW THIS LINE (UNTIL I SAY SO) -->
  <script language="javascript" type="text/javascript" src="libraries/p5.js"></script>
  <script language="javascript" type="text/javascript" src="p5js-temp-cartografia_del_fracaso7261114787448830096.js"></script>
  <!-- OK, YOU CAN MAKE CHANGES BELOW THIS LINE AGAIN -->

  <!-- This line removes any default padding and style. 
       You might only need one of these values set. -->
  <style> body {padding: 0; margin: 0;} </style>
</head>

<body>
</body>
</html>

assests/text.txt is simply a text file

@benfry benfry closed this as completed in 551e3b9 Jan 28, 2019
@benfry
Copy link
Contributor

benfry commented Jan 28, 2019

Fixed for the next release (1.1 of the Mode).

@github-actions
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jun 15, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants