Skip to content

Conversation

@jridgewell
Copy link

This saves and loads the current REPL state into the hash fragment, allow simple sharing. I've wanted this a few times when trying to demo different compression options.

Comment on lines +5 to +21
const base64UrlDecodeChars = {'-': '+', '_': '/', '.': '='};
const base64UrlDecode = input => {
try {
return atob(input.replace(/[-_.]/g, c => base64UrlDecodeChars[c]));
} catch {
return null;
}
}

const base64UrlEncodeChars = {'+': '-', '/': '_', '=': '.'};
const base64UrlEncode = input => {
try {
return btoa(input).replace(/[+/=]/g, c => base64UrlEncodeChars[c]);
} catch {
return null;
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Smart!

// Quote property names
opts = opts.replace(/^\s*(\w+):/gm, '"$1":');
return JSON.parse(opts);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see why this is something we need to do (avoiding a self xss and whatnot), however there are some Terser options that are regexps. For instance you can use /^_/ to select properties started with _ to mangle :/

There are a few options that take functions too (which would be a nightmare) so I'm not mentioning that part.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's possible to avoid this by disabling sharing for options that include RegExps and functions. Then you can do eval freely, and only do JSON.parse in loadState

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

Successfully merging this pull request may close these issues.

2 participants