From e7796b45c99503548670436033a5e095d27d07a7 Mon Sep 17 00:00:00 2001 From: Logan Smyth Date: Sun, 17 Apr 2016 00:49:36 -0700 Subject: [PATCH] Add a fast path for checking for exact node types. In my unscientific tests locally, this look the time for generating 200 files down from 11.8 to 8.3 seconds. --- packages/babel-types/src/index.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/packages/babel-types/src/index.js b/packages/babel-types/src/index.js index ea4f785c12..e7e63eb126 100644 --- a/packages/babel-types/src/index.js +++ b/packages/babel-types/src/index.js @@ -96,6 +96,10 @@ export function is(type: string, node: Object, opts?: Object): boolean { export function isType(nodeType: string, targetType: string): boolean { if (nodeType === targetType) return true; + // This is a fast-path. If the test above failed, but an alias key is found, then the + // targetType was a primary node type, so there's no need to check the aliases. + if (t.ALIAS_KEYS[targetType]) return false; + let aliases: ?Array = t.FLIPPED_ALIAS_KEYS[targetType]; if (aliases) { if (aliases[0] === nodeType) return true;