Skip to content

Commit

Permalink
fixup! fix(compiler-cli): allow linker to process minified booleans
Browse files Browse the repository at this point in the history
  • Loading branch information
petebacondarwin committed Apr 22, 2021
1 parent a7c015b commit 264b31d
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
12 changes: 7 additions & 5 deletions packages/compiler-cli/linker/babel/src/ast/babel_ast_host.ts
Expand Up @@ -38,16 +38,18 @@ export class BabelAstHost implements AstHost<t.Expression> {
return num.value;
}

isBooleanLiteral(bool: t.Expression): bool is t.BooleanLiteral|MinifiedBooleanLiteral {
isBooleanLiteral(bool: t.Expression): boolean {
return t.isBooleanLiteral(bool) || isMinifiedBooleanLiteral(bool);
}

parseBooleanLiteral(bool: t.Expression): boolean {
assert(bool, this.isBooleanLiteral, 'a boolean literal');
if (isMinifiedBooleanLiteral(bool)) {
return !(bool as MinifiedBooleanLiteral).argument.value;
if (t.isBooleanLiteral(bool)) {
return bool.value;
} else if (isMinifiedBooleanLiteral(bool)) {
return !bool.argument.value;
} else {
throw new FatalLinkerError(bool, 'Unsupported syntax, expected a boolean literal.')
}
return bool.value;
}

isArrayLiteral = t.isArrayExpression;
Expand Down
Expand Up @@ -111,6 +111,8 @@ describe('BabelAstHost', () => {
expect(host.isBooleanLiteral(expr('null'))).toBe(false);
expect(host.isBooleanLiteral(expr('\'a\' + \'b\''))).toBe(false);
expect(host.isBooleanLiteral(expr('\`moo\`'))).toBe(false);
expect(host.isBooleanLiteral(expr('!2'))).toBe(false);
expect(host.isBooleanLiteral(expr('~1'))).toBe(false);
});
});

Expand Down
Expand Up @@ -109,6 +109,8 @@ describe('TypeScriptAstHost', () => {
expect(host.isBooleanLiteral(expr('null'))).toBe(false);
expect(host.isBooleanLiteral(expr('\'a\' + \'b\''))).toBe(false);
expect(host.isBooleanLiteral(expr('\`moo\`'))).toBe(false);
expect(host.isBooleanLiteral(expr('!2'))).toBe(false);
expect(host.isBooleanLiteral(expr('~1'))).toBe(false);
});
});

Expand Down

0 comments on commit 264b31d

Please sign in to comment.