Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • S sweet-core
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 62
    • Issues 62
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 4
    • Merge requests 4
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • sweet-js
  • sweet-core
  • Merge requests
  • !204

Fix name clash for global leaks when using --readable-names

  • Review changes

  • Download
  • Email patches
  • Plain diff
Merged Administrator requested to merge github/fork/natefaubion/global-names into master Jan 16, 2014
  • Overview 1
  • Commits 2
  • Pipelines 0
  • Changes 3

Created by: natefaubion

This is a bit of an obscure bug, but can come up if you're using --readable-names and messing around with hygiene. Normally, it would result in a ReferenceError or something at runtime, but --readable-names could mask the issue, resulting in hard to track down bugs.

Take this code:

macro clobber {
  case { _ $body } => {
    var b = #{ $body };
    b[0].context = null;
    return b;
  }
}

var a = 12;
function foo() {
  var a = 1;
  var b = clobber a;
  return b;
}

Normally, this would be compiled as such:

var a$281 = 12;
function foo$282() {
    var a$283 = 1;
    var b$285 = a;
    return b$285;
}

Notice the a reference doesn't have a hygiene tag because we clobbered it's context. With --readable-names this would get expanded to:

var a = 12;
function foo() {
    var a$2 = 1;
    var b = a;
    return b;
}

Notice how the a in b = a would refer to the outer a? This PR splits --readable-names into two passes on the AST: one to gather all the non-static/global reference, and one to mangle. It will now expand correctly to:

var a$2 = 12;
function foo() {
    var a$3 = 1;
    var b = a;
    return b;
}

Preserving the same hygiene as the expansion without --readable-names.

Assignee
Assign to
Reviewers
Request review from
Time tracking
Source branch: github/fork/natefaubion/global-names