mirror of
https://github.com/facebook/react.git
synced 2026-02-24 04:33:04 +00:00
Add a gulp script for extracting error codes (#6882)
This commit is contained in:
27
scripts/error-codes/evalToString.js
Normal file
27
scripts/error-codes/evalToString.js
Normal file
@@ -0,0 +1,27 @@
|
||||
/**
|
||||
* Copyright (c) 2013-present, Facebook, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This source code is licensed under the BSD-style license found in the
|
||||
* LICENSE file in the root directory of this source tree. An additional grant
|
||||
* of patent rights can be found in the PATENTS file in the same directory.
|
||||
*
|
||||
* @flow
|
||||
*/
|
||||
'use strict';
|
||||
|
||||
function evalToString(ast/* : Object */)/* : string */ {
|
||||
switch (ast.type) {
|
||||
case 'StringLiteral':
|
||||
return ast.value;
|
||||
case 'BinaryExpression': // `+`
|
||||
if (ast.operator !== '+') {
|
||||
throw new Error('Unsupported binary operator ' + ast.operator);
|
||||
}
|
||||
return evalToString(ast.left) + evalToString(ast.right);
|
||||
default:
|
||||
throw new Error('Unsupported type ' + ast.type);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = evalToString;
|
||||
Reference in New Issue
Block a user