mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
chore: Extract codegen ParserError from flow and typescript into a common file (#34874)
Summary: This PR extracts the `ParserError` class from the `error.js` files from the flow and typescript folders into a single file in their parent folder in order to reduce the amount of duplicated code as requested on https://github.com/facebook/react-native/issues/34872 ## Changelog [Internal] [Changed] - Extract codegen `ParserError` from flow and typescript folders into a common file Pull Request resolved: https://github.com/facebook/react-native/pull/34874 Test Plan: Run `yarn jest react-native-codegen` and ensure CI is green  Reviewed By: cipolleschi Differential Revision: D40133301 Pulled By: cipolleschi fbshipit-source-id: 060571cf993672a9d03003e1a1a7c2aa2f381123
This commit is contained in:
committed by
Facebook GitHub Bot
parent
24efebf83d
commit
7227bdec8e
@@ -11,7 +11,7 @@
|
||||
'use strict';
|
||||
|
||||
const invariant = require('invariant');
|
||||
const {ParserError} = require('../errors');
|
||||
const {ParserError} = require('../../errors');
|
||||
|
||||
class MisnamedModuleFlowInterfaceParserError extends ParserError {
|
||||
constructor(hasteModuleName: string, id: $FlowFixMe) {
|
||||
|
||||
+1
-1
@@ -10,7 +10,7 @@
|
||||
|
||||
'use strict';
|
||||
|
||||
const {ParserError} = require('./errors');
|
||||
const {ParserError} = require('../errors');
|
||||
|
||||
/**
|
||||
* This FlowFixMe is supposed to refer to an InterfaceDeclaration or TypeAlias
|
||||
|
||||
@@ -1,36 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*
|
||||
* @flow strict-local
|
||||
* @format
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
class ParserError extends Error {
|
||||
nodes: $ReadOnlyArray<$FlowFixMe>;
|
||||
constructor(
|
||||
hasteModuleName: string,
|
||||
astNodeOrNodes: $FlowFixMe,
|
||||
message: string,
|
||||
) {
|
||||
super(`Module ${hasteModuleName}: ${message}`);
|
||||
|
||||
this.nodes = Array.isArray(astNodeOrNodes)
|
||||
? astNodeOrNodes
|
||||
: [astNodeOrNodes];
|
||||
|
||||
// assign the error class name in your custom error (as a shortcut)
|
||||
this.name = this.constructor.name;
|
||||
|
||||
// capturing the stack trace keeps the reference to your error class
|
||||
Error.captureStackTrace(this, this.constructor);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
ParserError,
|
||||
};
|
||||
@@ -11,7 +11,7 @@
|
||||
'use strict';
|
||||
|
||||
const invariant = require('invariant');
|
||||
const {ParserError} = require('../errors');
|
||||
const {ParserError} = require('../../errors');
|
||||
|
||||
class MisnamedModuleTypeScriptInterfaceParserError extends ParserError {
|
||||
constructor(hasteModuleName: string, id: $FlowFixMe) {
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
|
||||
'use strict';
|
||||
|
||||
const {ParserError} = require('./errors');
|
||||
const {ParserError} = require('../errors');
|
||||
const {parseTopLevelType} = require('./parseTopLevelType');
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user