• Jackson Ray Hamilton's avatar
    Automatically detect JSX in JavaScript files · bf37078d
    Jackson Ray Hamilton authored
    * lisp/files.el (auto-mode-alist): Simply enable
    javascript-mode (js-mode) when opening “.jsx” files, since the “.jsx”
    file extension will be used as an indicator of JSX syntax by js-mode,
    and more code is likely to work in js-mode than js-jsx-mode, and we
    probably want to guide users to use js-mode (with js-jsx-syntax)
    instead.  Code that used to work exclusively in js-jsx-mode (if anyone
    ever wrote any) ought to be updated to work in js-mode too when
    js-jsx-syntax is set to t.
    
    * lisp/progmodes/js.el (js-jsx-detect-syntax, js-jsx-regexps)
    (js-jsx--detect-and-enable, js-jsx--detect-after-change): New
    variables and functions for detecting and enabling JSX.
    
    (js-jsx-syntax): Update docstring with respect to the widened scope of
    the effects and use of this variable.
    
    (js-syntactic-mode-name, js--update-mode-name)
    (js--idly-update-mode-name, js-jsx-enable): New variable and functions
    for indicating when JSX is enabled.
    
    (js-mode): Detect and enable JSX.  Print all enabled syntaxes after
    the mode name whenever Emacs goes idle; this ensures lately-enabled
    syntaxes are evident.
    
    (js-jsx-mode): Update mode name for consistency with the state in
    which JSX is enabled in js-mode.  Update docstring to suggest
    alternative means of using JSX without this mode.  Going forward, it
    may be best to gently guide users away from js-jsx-mode, since a “one
    mode per syntax extension” model would not scale well if more syntax
    extensions were to be simultaneously supported (e.g. Facebook’s
    “Flow”).
    bf37078d
js.el 162 KB