【问题标题】:What is JSXIdentifier and how it differs from Identifier in AST?什么是 JSXIdentifier,它与 AST 中的 Identifier 有何不同?
【发布时间】:2016-03-18 09:29:15
【问题描述】:

在 JSX 扩展中定义

interface JSXIdentifier <: Identifier {
    type: "JSXIdentifier";
}

JSXIdentifier 与 AST 中的普通标识符的目的是什么? https://github.com/facebook/jsx/blob/master/AST.md

【问题讨论】:

    标签: javascript abstract-syntax-tree jsx


    【解决方案1】:

    好的,看起来JSXIdentifier 大致对应于 JSX 虚拟 DOM 中的组件或标签名称。例如在代码中

    <ul></ul> 
    

    JSXOpeningElement 会有一个孩子 JSXIdentifier,名字设置为“ul”

    {
      name {
         name : "ul", 
         type: "JSXIdentifier",
         ...
      },
      type: "JSXOpeningElement",
      ...
    }
    

    原因是为了将 JavaScript 标识符与 Virtual DOM 元素或 React 类名区分开来。

    因此,普通的 Identifier 是指 JavaScript 执行上下文变量,而 JSXIdentifier 是指虚拟 DOM 或 React 类名称。

    【讨论】:

      猜你喜欢
      • 2021-02-12
      • 2011-11-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-05-26
      • 2014-02-27
      • 2016-12-09
      相关资源
      最近更新 更多