Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/445.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/git/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 合并冲突在React、Typescript项目中如何有效_Javascript_Git_Reactjs_Typescript_Jsx - Fatal编程技术网

Javascript 合并冲突在React、Typescript项目中如何有效

Javascript 合并冲突在React、Typescript项目中如何有效,javascript,git,reactjs,typescript,jsx,Javascript,Git,Reactjs,Typescript,Jsx,我在下面的React/Typescript-JSX/TSX项目中找到了粘贴的代码。它包含尚未解决的Git合并冲突 代码通过保险丝盒生成并在浏览器中运行 传输的代码导致顶部元素被解析为组件的根元素,第二个元素以.app container开头被忽略 看起来,在某些情况下,可以通过TSX/JSX解释/解析/转换忽略git合并冲突 我的问题是:这是如何工作的?这种行为是故意的吗 export const App: SFC = () => ( <<<<<<<

我在下面的React/Typescript-JSX/TSX项目中找到了粘贴的代码。它包含尚未解决的Git合并冲突

代码通过保险丝盒生成并在浏览器中运行

传输的代码导致顶部元素被解析为组件的根元素,第二个元素以.app container开头被忽略

看起来,在某些情况下,可以通过TSX/JSX解释/解析/转换忽略git合并冲突

我的问题是:这是如何工作的?这种行为是故意的吗

export const App: SFC = () => (
<<<<<<< HEAD
    <Provider store={window.uglySolution}>
        <Router history={customHistory}>
            <Switch>
                <Route exact path='/' component={Welcome}/>
                <Route exact path='/advice' component={PageLayout}/>
                <Route exact path='/login' component={Login}/>
                <Route exact path='/manage' component={ManageLayout}/>
            </Switch>
        </Router>
    </Provider>
=======
    <div className='app-container'>
        <Provider store={window.uglySolution}>
            <Router history={customHistory}>
                <Switch>
                    <Route exact path='/' component={Welcome}/>
                    <Route exact path='/advice' component={PageLayout}/>
                    <Route exact path='/login' component={Login}/>
                    <Route exact path='/manage' component={ManageLayout}/>
                </Switch>
            </Router>
        </Provider>
    </div>
>>>>>>> f81b0b1b458e3d41f91faa2e726be6d88a35d9f8
);
看起来,在某些情况下,git合并冲突可以通过Tax/JSX解释/解析/转换来解决

给定的代码是编译错误。也就是说,编译错误并不意味着没有生成任何JS。有一个选项noEmitOnError可以防止出现这种情况,但这意味着即使没有此选项,您也应该看到编译错误并修复它

更多
我知道这是一个相当晚的答案,差不多一年后,但万一有人在谷歌上搜索这个,并想知道同样的事情。是的,在typescript lexer中有处理git合并冲突的代码!注意:在解析器上跳过细节默认为true

if (isConflictMarkerTrivia(text, pos)) {
  pos = scanConflictMarkerTrivia(text, pos, error);
  if (skipTrivia) {
    continue;
}
else {
    return token = SyntaxKind.ConflictMarkerTrivia;
  }
}
下面是处理合并冲突的代码:

function scanConflictMarkerTrivia(text: string, pos: number, error?: (diag: DiagnosticMessage, pos?: number, len?: number) => void) {
    if (error) {
        error(Diagnostics.Merge_conflict_marker_encountered, pos, mergeConflictMarkerLength);
    }

    const ch = text.charCodeAt(pos);
    const len = text.length;

    if (ch === CharacterCodes.lessThan || ch === CharacterCodes.greaterThan) {
        while (pos < len && !isLineBreak(text.charCodeAt(pos))) {
            pos++;
        }
    }
    else {
        Debug.assert(ch === CharacterCodes.bar || ch === CharacterCodes.equals);
        // Consume everything from the start of a ||||||| or ======= marker to the start
        // of the next ======= or >>>>>>> marker.
        while (pos < len) {
            const currentChar = text.charCodeAt(pos);
            if ((currentChar === CharacterCodes.equals || currentChar === CharacterCodes.greaterThan) && currentChar !== ch && isConflictMarkerTrivia(text, pos)) {
                break;
            }

            pos++;
        }
    }

    return pos;
}
资料来源:

如果不告诉tsc,tsc将采取其他措施,最好忽略您可能遇到的任何错误代码。这可能会产生有效的代码,即使输入错误。这是默认行为,但我不会指望它。。解决你的矛盾还有,在这种情况下。。我假设git中的合并文本最终会出现在模板中。。因为从tsc的角度来看text@toskv-在这种情况下,我如何告诉Typescript忽略错误代码或其他语句?是-noemitError编译器选项控制发生的情况,默认值为false。您可以在这里看到所有配置。在您的例子中,可能是您拥有的是有效的jsx,因为git标记被认为是html文本,并且被编译器忽略。您可以责怪git没有更好的合并机制..:D