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

Change assert to allow blank strings #1177

Merged
merged 5 commits into from
Mar 31, 2020
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/program.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1044,7 +1044,9 @@ export class Program extends DiagnosticEmitter {
// TODO: for (let [alias, name] of globalAliases) {
for (let _keys = Map_keys(globalAliases), i = 0, k = _keys.length; i < k; ++i) {
let alias = unchecked(_keys[i]);
let name = assert(globalAliases.get(alias));
let name = globalAliases.get(alias);
Copy link
Member

@dcodeIO dcodeIO Mar 16, 2020

Choose a reason for hiding this comment

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

Can just use changetype<string>(globalAliases.get(alias)) since the value can't be null

Copy link
Contributor Author

Choose a reason for hiding this comment

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

but it can be undefined right?

alias = "bad key"
let name = changetype<string>(globalAliases.get(alias))
if (!name.length) continue; // explicitly disabled

throws

ERROR: TypeError: Cannot read property 'length' of undefined

I suppose that's not really much different than the assertion though and shouldn't really happen anyway

Copy link
Member

Choose a reason for hiding this comment

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

Hmm, yeah, that's strange. Might be cli/asc.js wrongly inserting an undefined into the map.

Copy link
Member

@dcodeIO dcodeIO Mar 16, 2020

Choose a reason for hiding this comment

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

Btw, alias = "bad key" doesn't happen since we _keys = Map_keys(globalAliases) so we know the key is in there

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah okay- well in that case maybe we should just use ! and ignore the undefined case

assert(isString(name));
name = name!
if (!name.length) continue; // explicitly disabled
let firstChar = name.charCodeAt(0);
if (firstChar >= CharCode._0 && firstChar <= CharCode._9) {
Expand Down