Skip to content
This repository has been archived by the owner on Mar 25, 2021. It is now read-only.

Set --lib es6, and use Map/Set methods where possible. #1984

Merged
merged 9 commits into from
Jan 7, 2017

Conversation

andy-hanson
Copy link
Contributor

@andy-hanson andy-hanson commented Jan 5, 2017

PR checklist

What changes did you make?

Set the "lib" option to ["es6", "dom"] ("dom" typings used by underscore).
EDIT: Removed underscore; it's only used by 1 function, camelize, that's a one-liner. Their source, mine.

Used Map and Set in cases where their absence appeared to have been compensated for.

Is there anything you'd like reviewers to focus on?

It's more efficient to lookup in a Map only once, so avoid this pattern:

if (map.has(key)) {
	use(map.get(key))
}

Prefer:

const got = map.get(key);
if (got !== undefined) {
	use(got);
}

@andy-hanson andy-hanson force-pushed the es6 branch 2 times, most recently from ba5787c to 5e72879 Compare January 5, 2017 03:04
this.addFailureAtNode(node, Rule.FAILURE_STRING);
}
const isNumber = node.kind === ts.SyntaxKind.NumericLiteral && !Rule.ALLOWED_NODES.has(node.parent!.kind);
const isMagicNumber = (isNumber || isUnary) && !this.allowed.has(node.getText());
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Seems like the isUnary case should also check for ALLOWED_NODES, but this is what it did before.

Copy link
Contributor

Choose a reason for hiding this comment

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

Agree. Opened issue #2005


class PreferForOfWalker extends Lint.BlockScopeAwareRuleWalker<{}, IncrementorMap> {
public createScope() {
return {};
return new Map();
Copy link
Contributor

Choose a reason for hiding this comment

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

this method could just return void (need to update type parameters). scope is never used anywhere, only blockScope is needed.

@andy-hanson andy-hanson mentioned this pull request Jan 7, 2017
5 tasks
Copy link
Contributor

@nchen63 nchen63 left a comment

Choose a reason for hiding this comment

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

much cleaner

@@ -21,11 +21,10 @@ import {IOptions} from "../rule/rule";
import {RuleWalker} from "./ruleWalker";

export class SkippableTokenAwareRuleWalker extends RuleWalker {
protected tokensToSkipStartEndMap: {[start: number]: number};
private tokensToSkipStartEndMap = new Map<number, number>();

constructor(sourceFile: ts.SourceFile, options: IOptions) {
Copy link
Contributor

Choose a reason for hiding this comment

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

don't need constructor anymore

this.addFailureAtNode(node, Rule.FAILURE_STRING);
}
const isNumber = node.kind === ts.SyntaxKind.NumericLiteral && !Rule.ALLOWED_NODES.has(node.parent!.kind);
const isMagicNumber = (isNumber || isUnary) && !this.allowed.has(node.getText());
Copy link
Contributor

Choose a reason for hiding this comment

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

Agree. Opened issue #2005

@nchen63 nchen63 merged commit 4ee7839 into palantir:master Jan 7, 2017
@nchen63
Copy link
Contributor

nchen63 commented Jan 7, 2017

@andy-hanson thanks!

@andy-hanson andy-hanson deleted the es6 branch January 7, 2017 17:16
@adidahiya
Copy link
Contributor

this is an awesome PR, thanks @andy-hanson

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants