Coder Social home page Coder Social logo

gandm / language-babel Goto Github PK

View Code? Open in Web Editor NEW
476.0 10.0 87.0 4.12 MB

ES2017, flow, React JSX and GraphQL grammar and transpilation for ATOM

Home Page: https://atom.io/packages/language-babel

License: MIT License

CSS 1.65% CoffeeScript 86.87% JavaScript 11.48%
atom react jsx es5 es7 babel graphql styled-components es6

language-babel's Introduction

language-babel

Build Status Build status Build Dependencies

Language grammar for all versions of JavaScript including ES2016 and ESNext, JSX syntax as used by Facebook React, Atom's etch and others, as well as optional typed JavaScript using Facebook flow. This package also supports highlighting of GraphQL language constructs when inside certain JavaScript template strings. For .graphql and .gql file support please see language-graphql . The colour of syntax is determined by the theme in use.

The package also provides

By default the language-babel package will detect file types .js,.babel,.jsx, .es, .es6, .mjs and .flow. Use the standard ATOM interface to enable it for other file types. This provides a grammar that scopes the file in order to colour the text in a meaningful way. If other JavaScript grammars are enabled these may take precedence over language-babel. Look at the bottom right status bar indicator to determine the language grammar of a file being edited. language-babel will be shown as either Babel or Babel ES6 JavaScript. Clicking the name will allow the grammar for a file to be changed.

language-babel provides Babel V6 & V5 transpiler support. If you only require grammar/syntax highlighting ensure that the package settings Transpile On Save and Allow Local Override are both off.

Installation

Install via ATOM or by using apm install language-babel. If you only need to use the provided grammar read no further!

Auto Completion of JSX tags, elements and attributes

JSX tag closures are provided as auto-complete options. In addition, common HTML elements and their associated properties are displayed as auto-complete lists. Those supported by language-babel are described here

autoclose

Commenting out JSX elements

JSX elements cannot be commented out by using standard // or /* */ commenting. Normally {/* */} is used instead. language-babel changes the Atom toggle comments behaviour when inside a JSX block to support this behaviour. Nested elements within JSX that require a // form of commenting will be detected automatically.

autoclose

Automatic insertion between JSX tags

When a newline is inserted between a matched open/close pair of JSX tags, language-babel inserts an additional line and positions the cursor. If Auto Indent is also turned on then the cursor is correctly indented.

autoclose

Automatic Indenting of JSX

The package setting Auto Indent JSX if enabled will auto-indent any JSX code typed or moved across using suitable Atom defaults. There are also three commands - language-babel:toggle-auto-indent-jsx, language-babel:auto-indent-jsx-on and language-babel:auto-indent-jsx-off that override the default behaviour. These can be mapped to keyboard shortcuts if needed.

Auto-Indenting will also attempt to read the .eslintrc file associated with an edited file's project for the presence of four properties whose defaults are shown below. These rules, which are part of the ESLint-plugin-React EsLint plugin, are then used to determine the alignment and tab/spaces spacing of JSX elements. For more information on the options for these rules see Closing bracket, Indent and Indent Props.

Please note that no attempt is currently made to read eslint settings in any other file. e.g. package.json, eslint.js, extends..., etc.

{
  "rules": {
    "indent": 1,
    "react/jsx-closing-bracket-location": 1,
    "react/jsx-indent-props": 1,
    "react/jsx-indent": 1
  }
}

When moving around a JSX block language-babel reformats the preceding JSX lines automatically. Lines following the cursor are not indented. This is to protect the source code following incomplete JSX from being processed. The user should correctly position the first JSX element as auto-indenting will not do this.

You may also turn off automatic indenting for all files by setting the package option Auto Indent JSX

indent

Interface to Babel v7, v6 & v5.

language-babel fully supports the Babel JavaScript transpiler versions 5, 6 and 7.

Options in the language-babel package settings and/or in .languagebabel project based JSON files allow for Babel validations to be carried out on a file saves using .babelrc options. A file tree context menu - Language-Babel - is also provided that allows whole directories to be transpiled obeying any .babelrc and .languagebabel settings. Even if using a workflow such as gulp, webpack, etc, this can be very useful. Additional options allow the output from Babel (transpiled code and maps ) to be output to other directories.

It is also possible to preview any source file as Babel would output it.

Previewing

Babel code can be previewed as shown below. Source mapping keeps the ES201x file's cursor in step with the transpiled code's cursor. This feature requires the Atom package source-preview in which language-babelbecomes a provider of transpiled output which source-preview consumes.

Please note that the following two packages should be disabled or uninstalled to stop multiple packages contending for the same transpile - source-preview-babel and source-preview-react.

source-preview provides a keyboard toggle to view the current file. As with transpiling described below, a project must have the relevant .babelrc, package.json and node_modules

example

Transpiling

This package works by using the concept of a project folder which we assume contains a project or even nested projects any of which may contain a Babel project. In a Babel project, we expect to see one or more .babelrc files, node_modules folders at the root's of the project containing an optional @babel/core babel-core and other babel plugins/presets as determined by the project's package.json file. In addition, we may expect to see one or more .languagebabel files in the project. Projects are either implicit (an Atom project folder) or explicit (denoted by a .languagebabel property of "projectRoot": true). If no @babel/core or babel-core is found in the project then a check is made to determine if this is part of a Yarn workspace and if so a further check is made in the workspace node_modules for @babel/core or babel-core. If none are found then a version will be provided by language-babel but this will be a Babel Version 6 instance. Plugins and presets will not be provided by the package.

A trivial example project that shows examples of using .languagebabel and .babelrc files may be found here.

example

Multiple projects may be open at any time inside Atom and language-babel must allow the use of differing babel-core versions and associated plugins when transpiling. It does this by using background tasks - one per Babel project. When a language-babel grammar enabled file is saved the package settings and optionally any .languagebabel configuration files are read to determine if the file should be transpiled and what to do with the output. These settings and .languagebabel options are described below.

It is very easy to ensure that language-babel does not transpile files that are not needed. Just turn off the global package setting Transpile On Save and turn on Allow Local Override. Apart from grammar highlighting only projects having a .languagebabel in the file path will then be affected by this package. Further granularity is easy too.

If .babelrc and/or package.json files contain Babel properties that are environment specific these environments should be created before Atom is started. In particular, Babel assumes a development environment by default, whereas Atom assumes a production environment by default.

e.g.

Windows

set NODE_ENV="development"
atom

OSX/Unix

NODE_ENV="development"
atom

Package Settings

For most projects, it is better to configure language-babel via project-based .languagebabel file properties which will override the package settings below. See ".langeuagebabel Configuration" for more information on this behaviour.

  • Allow Local Override

    If set this allows .languagebabel file properties to override the global package settings.

  • Transpile On Save

    On any file save of a language-babel grammar enabled file the Babel transpiler is called. No actual transpiled file is saved but any Babel errors and/or successful indicators are notified by an ATOM pop-up. Not all files are candidates for transpilation as other settings can affect this. For example see Disable When No Babelrc File In Path and Babel Source Path below.

    {"transpileOnSave": true} or
    {"transpileOnSave": false}
  • Create Transpiled Code

    If enabled together with Transpile On Save this will output JavaScript code to a .js file with the same prefix as the original. By using the Babel Transpile Path options it is possible to transpile to a different target directory. Not all files are candidates for transpilation as other settings can affect this.

    {"createTranspiledCode": true} or
    {"createTranspiledCode": false}
  • Disable When No Babelrc File In Path

    Disables transpiler if no .babelrc files are found in the source file path.

    {"disableWhenNoBabelrcFileInPath": true} or
    {"disableWhenNoBabelrcFileInPath": false}
  • Suppress Transpile On Save Messages

    Suppress all successful save messages. Errors are still notified.

    {"suppressTranspileOnSaveMessages": true} or
    {"suppressTranspileOnSaveMessages": false}
  • Suppress Source Path Messages

    This is set by default so that when a file is saved that is outside the Babel Source Path directory no message is generated. This is particularly useful when you have mixed ES2015 and ES3-5 environment. ES2015 files can be placed inside a Babel Source Path where they will be transpiled and other files will not pop up annoying messages when being saved.

    {"suppressSourcePathMessages": true} or
    {"suppressSourcePathMessages": false}
  • Create Map

    If transpiled output is being saved a separate source map can be also be saved. The source file name will be used with a new suffix of .js.map and sent to a directory specified in Babel Maps Path.

    If .babelrc files use the sourceMaps: inline or sourceMaps both option, turn this createMap option off as the map data is stored as part of the source file.

    {"createMap": true} or
    {"createMap": false}
  • Babel Maps Add Url

    If a source map is created using the Create Map option above then this appends a Url reference //# sourceURL=sourcefile.js.map to the transpiled JavaScript file.

    {"babelMapsAddUrl": true} or
    {"babelMapsAddUrl": false}
  • Project Root ( only present in .languagebabel files)

    A .languagebabel property that defines this directory is a project root. A project root would contain a node_modules folder with an optional babel-core as well as any plugins required.

    {"projectRoot": true} or
    {"projectRoot": false}
  • Babel Source Path, Babel Transpile Path and Babel Maps Path

    These a directories based on the project root. A project root is either implicit ( based on an Atom folders root directory) or explicit ( based upon the root defined in the nearest .languagebabel file with a property "projectRoot": true )

    Only files found under the project/babelsourcepath will be candidates for transpilation. If multiple project root folders exist then babelsourcepath may exist in any or all folders.

    The Transpile and Maps paths allow different target directories to be specified. If multiple project root folders exist then they may exist in any or all folders.

    e.g. Two project root folders exist /proj1 and /proj2. If Source Path is set to babelSourcethe Transpile Path is set to babelTranspile and the Maps Path is set to babelMaps then:-

    /proj1/babelSource/foo.es6 ->/proj1/babelTranspile/foo.js,/proj1/babelMaps/foo.js.map

    {
      "projectRoot":  true,    
      "babelSourcePath": "babelSource",
      "babelTranspilePath": "babelTranspile",
      "babelMapsPath": "babelMaps"
    }

    /proj2/babelSource/dirBar/foo.es6 -> /proj2/lib/foo.js,/proj2/lib/foo.js.map

    {
      "projectRoot":  true,
      "babelSourcePath": "babelSource/dirBar",
      "babelTranspilePath": "lib",
      "babelMapsPath": "lib"
    }
  • Create Target Directories

    When enabled any target directories that do not exist will be created prior to a transpilation.

    {"createTargetDirectories": true} or
    {"createTargetDirectories": false}
  • Keep File Extension

    Keeps the source filename extension as the target filename extension

  • Auto Indent JSX

    Enables automatic indenting of JSX.

  • JavaScript Tagged Template Literal Grammar Extensions

    This package setting allows language-babel to include third party grammars to highlight code inside template literal strings. These may be tagged template literals, described here, or where no appropriate function tag exists, another form of tag marking that signifies the templates nature. e.g. A comment string.

    For example you may wish to highlight templates prefixed with /* @html */`<div></div>` as HTML, and maybe sql`select * from table foo` as SQL. The latter assumes a tagged function named sql exists in the code.

    In order to do this, you need to find a language package that supports the highlighting of the template code. This language package should then be installed into Atom. You then need to find the scope name for that grammar. This can be done in a number of ways, but if you view the grammars JSON/CSON file and look for the scopeName property field, this indicates the scope name for that grammar.

    If we use the Atom provided languages language-css, language-html and language-sql in our example above to highlight the template code, then this field would look like.

    "(?:css\.(?:[a-z])+)":source.css, /* @html */:text.html.basic, sql:source.sql

    In other words, the package settings for this field is an array of strings, with each string in the form of template-prefix:grammar-scopename#optional-include.

    where:

    • template-prefix is a literal string or an Oniguruma regular expression ( Oniguruma is the regular expression engine for TextMate grammars used by Atom) that comes before the opening back-tick of a template. A literal string may contain any characters except a comma but including colons. A regular expression is denoted by being enclosed by double quote marks "RegExp Here". Most importantly, a regular expression should create no capturing groups.
    • :The last colon in the string signifies the start of the embedded grammars scopeName.
    • grammar-scopename is the scopeName of the grammar used to highlight the template.
    • #optional-include if present, will use that include block in the grammars repository.

    Please note: As language-babel passes off highlighting of the template to another grammar, it cannot highlight any interpolated code. Actually, that's not strictly correct, as it does highlight interpolated JavaScript code but only at the top most rule stack of the embedded grammar, but this is unlikely to be useful with most grammars. Also note that there is a delay of 10 seconds between the last character being entered into this field and a new extension grammar being generated.

  • Styled-Components Auto-Complete Method

    This flag if set will enable Emmet snippets to be used inside CSS templates. If a valid emmet abbreviation is entered then the expanded snippet will appear at the top of a auto-complete list. Pressing the appropriate auto-complete key (normally tab) will expand the snippet.

.languagebabel Configuration

.languagebabel JSON configuration files can exist in any directory of the path that contains a source file to be compiled. The properties in this file override the global package settings above. If .languagebabel files are present, they read and merged starting in the source files directory up to the project root directory. Properties defined closest the source file take precedence.

To use this option please enable the Allow Local Override package setting.

A .languagebabel file may contain one or more of the following properties.

{
  "babelMapsPath":                    "relPath",
  "babelMapsAddUrl":                  true|false,
  "babelSourcePath":                  "relPath",
  "babelTranspilePath":               "relPath",
  "createMap":                        true|false,
  "createTargetDirectories":          true|false,
  "createTranspiledCode":             true|false,
  "disableWhenNoBabelrcFileInPath":   true|false,
  "keepFileExtension":                true|false,
  "projectRoot":                      true|false,  
  "suppressSourcePathMessages":       true|false,
  "suppressTranspileOnSaveMessages":  true|false,
  "transpileOnSave":                  true|false
}

GraphQL Code Highlighting

language-babel supports highlighting of GraphQL code within JavaScript files. For highlighting .graphql and .gql files see its sister grammar - language-graphql.

Inside JavaScript, GraphQL enclosed in back-ticks, a.k.a. Quasi or template strings are highlighted. Other GraphQL structures, notably types, are supported by the Flow component of this package.

Strings that have one of three prefixes/tags are parsed by the grammar to highlight the code enclosed.

Relay.QL`This is how Relay uses template strings`

graphql`This is how Relay will use template strings`

gql`This is how Apollo for GraphQL uses template strings`

/* GraphQL */`For cases where no template tag function is available`

An example of using the third method for highlighting code using /* GraphQL */

var { graphql, buildSchema } = require('graphql');

var schema = buildSchema(/* GraphQL */`
  type Query {
    hello: String
  }
`);

language-babel's People

Contributors

aerijo avatar alexeyraspopov avatar aluisioasg avatar asiandrummer avatar bjohn465 avatar daltones avatar dimapaloskin avatar djhojd avatar etzos avatar felixakiragreen avatar gandm avatar glavin001 avatar hansonw avatar hyeonupark avatar iamkd avatar jamesernator avatar johngeorgewright avatar kassens avatar kevinastone avatar michaelficarra avatar mpacer avatar neyasov avatar nfour avatar rgbkrk avatar robertrossmann avatar spaintrain avatar sthub1 avatar vith avatar vovkasm avatar zertosh avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

language-babel's Issues

Known Grammar Limitations:-

This grammar has certain limitations.

  • let, var and const variables support flow typing but if used then the statement must be terminated with a semi-colon. Multiple variables and assignments may appear in the statement but the first must have a flow type else the grammar assumes no flow types for the remainder of the statement.
  • ES7 Class properties with flow typing must terminate with a semi-colon. e.g. static a: number = 1;
  • Arrow functions must have the => on the same line as the function name/literal and parameters.

Indentation of switch/case/default

Hey,
I really like the indentation and syntax highlighting the only thing bugging me is the non existing indentation of switch statements.
Currently this is the indentation provided:

switch(foo) {
  case 0:
  bar = batz;
  break;

I would love if you could make it like this:

switch(foo) {
  case 0:
    bar = batz;
    break;

Would increase readability by a lot.

babelrc seems to be ignored

To prevent from trying to compile *.js files, I added a .babelrc file with the following contents:

{
   "only": [ "*.es6" ]
}

This seems to be ignored, as I still get the error message "Transpiled file would overwrite source file. Aborted!" when editing a *.js file (in my case the Gruntfile.js).
In my setup I want all *.es6 files to be compiled to *.js files located next to their according source file.

I had a look at your source code at differently tagged versions and I saw, that reading the babelrc file was dropped starting with version 0.8.0. How is it supposed to work now?

Uncaught AssertionError: true === false with Atom 1.0.2 upgrade

Since upgrading atom today I'm getting this error all the time.

Uncaught AssertionError: true === false

/Applications/Atom.app/Contents/Resources/app.asar/src/pane.js:774
Hide Stack Trace
AssertionError: true === false
  at Def.Dp.bases (/Applications/Atom.app/Contents/Resources/app.asar/node_modules/babel-core/node_modules/ast-types/lib/types.js:408:12)
  at Object.<anonymous> (/Users/gbirman/.atom/packages/language-babel/node_modules/babel-core/lib/babel/patch.js:45:26)
  at Module._compile (module.js:452:26)
  at Object.loadFile [as .js] (/Applications/Atom.app/Contents/Resources/app.asar/src/babel.js:162:21)
  at Module.load (module.js:347:32)
  at Function.Module._load (module.js:302:12)
  at Module.require (module.js:357:17)
  at require (module.js:376:17)
  at Object.<anonymous> (/Users/gbirman/.atom/packages/language-babel/node_modules/babel-core/lib/babel/util.js:21:1)
  at Module._compile (module.js:452:26)
  at Object.loadFile [as .js] (/Applications/Atom.app/Contents/Resources/app.asar/src/babel.js:162:21)
  at Module.load (module.js:347:32)
  at Function.Module._load (module.js:302:12)
  at Module.require (module.js:357:17)
  at require (module.js:376:17)
  at Object.<anonymous> (/Users/gbirman/.atom/packages/language-babel/node_modules/babel-core/lib/babel/transformation/file/options/parsers.js:16:13)
  at Module._compile (module.js:452:26)
  at Object.loadFile [as .js] (/Applications/Atom.app/Contents/Resources/app.asar/src/babel.js:162:21)
  at Module.load (module.js:347:32)
  at Function.Module._load (module.js:302:12)
  at Module.require (module.js:357:17)
  at require (module.js:376:17)
  at Object.<anonymous> (/Users/gbirman/.atom/packages/language-babel/node_modules/babel-core/lib/babel/transformation/file/options/index.js:13:16)
  at Module._compile (module.js:452:26)
  at Object.loadFile [as .js] (/Applications/Atom.app/Contents/Resources/app.asar/src/babel.js:162:21)
  at Module.load (module.js:347:32)
  at Function.Module._load (module.js:302:12)
  at Module.require (module.js:357:17)
  at require (module.js:376:17)
  at Object.<anonymous> (/Users/gbirman/.atom/packages/language-babel/node_modules/babel-core/lib/babel/transformation/file/index.js:15:16)
  at Module._compile (module.js:452:26)
  at Object.loadFile [as .js] (/Applications/Atom.app/Contents/Resources/app.asar/src/babel.js:162:21)
  at Module.load (module.js:347:32)
  at Function.Module._load (module.js:302:12)
  at Module.require (module.js:357:17)
  at require (module.js:376:17)
  at Object.<anonymous> (/Users/gbirman/.atom/packages/language-babel/node_modules/babel-core/lib/babel/transformation/plugin.js:37:13)
  at Module._compile (module.js:452:26)
  at Object.loadFile [as .js] (/Applications/Atom.app/Contents/Resources/app.asar/src/babel.js:162:21)
  at Module.load (module.js:347:32)
  at Function.Module._load (module.js:302:12)
  at Module.require (module.js:357:17)
  at require (module.js:376:17)
  at Object.<anonymous> (/Users/gbirman/.atom/packages/language-babel/node_modules/babel-core/lib/babel/transformation/transformer.js:11:15)
  at Module._compile (module.js:452:26)
  at Object.loadFile [as .js] (/Applications/Atom.app/Contents/Resources/app.asar/src/babel.js:162:21)
  at Module.load (module.js:347:32)
  at Function.Module._load (module.js:302:12)
  at Module.require (module.js:357:17)
  at require (module.js:376:17)
  at Object.<anonymous> (/Users/gbirman/.atom/packages/language-babel/node_modules/babel-core/lib/babel/transformation/file/plugin-manager.js:15:20)
  at Module._compile (module.js:452:26)
  at Object.loadFile [as .js] (/Applications/Atom.app/Contents/Resources/app.asar/src/babel.js:162:21)
  at Module.load (module.js:347:32)
  at Function.Module._load (module.js:302:12)
  at Module.require (module.js:357:17)
  at require (module.js:376:17)
  at Object.<anonymous> (/Users/gbirman/.atom/packages/language-babel/node_modules/babel-core/lib/babel/transformation/pipeline.js:11:26)
  at Module._compile (module.js:452:26)
  at Object.loadFile [as .js] (/Applications/Atom.app/Contents/Resources/app.asar/src/babel.js:162:21)
  at Module.load (module.js:347:32)
  at Function.Module._load (module.js:302:12)
  at Module.require (module.js:357:17)
  at require (module.js:376:17)
  at Object.<anonymous> (/Users/gbirman/.atom/packages/language-babel/node_modules/babel-core/lib/babel/transformation/index.js:11:17)
  at Module._compile (module.js:452:26)
  at Object.loadFile [as .js] (/Applications/Atom.app/Contents/Resources/app.asar/src/babel.js:162:21)
  at Module.load (module.js:347:32)
  at Function.Module._load (module.js:302:12)
  at Module.require (module.js:357:17)
  at require (module.js:376:17)
  at Object.<anonymous> (/Users/gbirman/.atom/packages/language-babel/node_modules/babel-core/lib/babel/api/node.js:22:23)
  at Module._compile (module.js:452:26)
  at Object.loadFile [as .js] (/Applications/Atom.app/Contents/Resources/app.asar/src/babel.js:162:21)
  at Module.load (module.js:347:32)
  at Function.Module._load (module.js:302:12)
  at Module.require (module.js:357:17)
  at require (module.js:376:17)
  at Object.<anonymous> (/Users/gbirman/.atom/packages/language-babel/node_modules/babel-core/index.js:1:80)
  at Module._compile (module.js:452:26)
  at Object.loadFile [as .js] (/Applications/Atom.app/Contents/Resources/app.asar/src/babel.js:162:21)
  at Module.load (module.js:347:32)
  at Function.Module._load (module.js:302:12)
  at Module.require (module.js:357:17)
  at require (module.js:376:17)
  at Transpiler.transpile (/Users/gbirman/.atom/packages/language-babel/lib/transpiler.coffee:37:15)
  at /Users/gbirman/.atom/packages/language-babel/lib/babel-transpiler.coffee:17:21
  at Emitter.module.exports.Emitter.emit (/Applications/Atom.app/Contents/Resources/app.asar/node_modules/event-kit/lib/emitter.js:82:11)
  at TextBuffer.module.exports.TextBuffer.saveAs (/Applications/Atom.app/Contents/Resources/app.asar/node_modules/text-buffer/lib/text-buffer.js:996:20)
  at TextBuffer.module.exports.TextBuffer.save (/Applications/Atom.app/Contents/Resources/app.asar/node_modules/text-buffer/lib/text-buffer.js:978:19)
  at TextEditor.module.exports.TextEditor.save (/Applications/Atom.app/Contents/Resources/app.asar/src/text-editor.js:579:26)
  at Pane.module.exports.Pane.saveItem (/Applications/Atom.app/Contents/Resources/app.asar/src/pane.js:535:18)
  at Pane.module.exports.Pane.saveActiveItem (/Applications/Atom.app/Contents/Resources/app.asar/src/pane.js:518:19)
  at Workspace.module.exports.Workspace.saveActivePaneItem (/Applications/Atom.app/Contents/Resources/app.asar/src/workspace.js:592:35)
  at atom-workspace.atom.commands.add.core:save (/Applications/Atom.app/Contents/Resources/app.asar/src/workspace-element.js:311:30)
  at CommandRegistry.module.exports.CommandRegistry.handleCommandEvent (/Applications/Atom.app/Contents/Resources/app.asar/src/command-registry.js:241:29)
  at /Applications/Atom.app/Contents/Resources/app.asar/src/command-registry.js:3:61
  at KeymapManager.module.exports.KeymapManager.dispatchCommandEvent (/Applications/Atom.app/Contents/Resources/app.asar/node_modules/atom-keymap/lib/keymap-manager.js:520:16)
  at KeymapManager.module.exports.KeymapManager.handleKeyboardEvent (/Applications/Atom.app/Contents/Resources/app.asar/node_modules/atom-keymap/lib/keymap-manager.js:355:22)
  at HTMLDocument.module.exports.WindowEventHandler.onKeydown (/Applications/Atom.app/Contents/Resources/app.asar/src/window-event-handler.js:177:20)

The error was thrown from the language-babel package. You can help by creating an issue. Please explain what actions triggered this error.
Create issue on the language-babel package

Having problems with Spread Operator

Hi,
I just came to Atom world from Sublime and I'm trying to compile a .jsx component and when I try to save it always appears this message

Babel v5.6.15 Transpiler Error
/app/components/Lane.jsx: Unexpected token (35:18)

The line that is broking

const {i, name, ...props} = this.props;

Referring the spread operator.

flowtype support for let, var and const missing.

I haven't released support for typing a var. e.g. let a: string I have experimented with quite complex types for vars as well as multiple vars in a single statement with assignments and the only way I can make it work well is if I can guarantee a statement termination. e.g. ;

I will take another look given time.

Regex or escape character being highlighting in strings

Example

Here I want to type the instance where my sql server runs and it appears it's highlighting a javascript regex or escape character, the core javascript grammar behaves the same way.

I expected it would just highlight when it's one of those escape characters for e.g:

  • newline: \n
  • carriage return: \r
  • or escape quote: \'

How activate flow?

Should I install anything else to activate flow grammar? I put /* @flow */ at the beginning of file but there is no check of the file

Remove `label` from classes applied for syntax highlighting

Text that matches constant.other.object.key.js is being matched and having the classes string.unquoted.label.js applied. The .label class applies Bootstrap's CSS which has bold, a different font size, and padding, which all contribute to making the rendered text a headache to edit because the visible location of the cursor does not match the actual cursor position, and therefore I end up editing the wrong characters.

Example

Now the testWithLabel is default syntax highlighting. ing key is that is detected by another grammar pattern and correctly highlights. testWithoutLabel is what I expect to see, and I was able to accomplish by manually removing the label class from the element in the DOM.

Screenshot

image

Code

let obj = {
  testWithLabel: null,
  testWithoutLabel: null,
  ing: function() {

  }
};

Bug

See https://github.com/gandm/language-babel/blob/master/grammars/Babel%20Language.json#L197

Code

 "literal-labels": {
      "patterns": [
        {
          "begin": "(?<!\\?)(?<!\\?\\s)(?=(((')((?:[^']|\\\\')*)('))|((\")((?:[^\"]|\\\\\")*)(\")))\\s*:)",
          "end": ":",
          "endCaptures": {
            "0": { "name": "punctuation.separator.key-value.js" }
          },
          "patterns": [
            { "include": "#literal-string" }
          ]
        },
        {
          "name": "constant.other.object.key.js",
          "match": "(?<!\\.|\\?|\\?\\s)([_$a-zA-Z][$\\w]*)\\s*(:)",
          "captures": {
            "1": { "name": "string.unquoted.label.js" },
            "2": { "name": "punctuation.separator.key-value.js" }
          }
        }
      ]
    },

Suppress transpile-on-save success messages

Love the Atom plugin. But I get success on Save so often when I'm really only interested in transpile failures. I'd love to see a preference for suppressing notification for successes.

v0.13.3 broke syntax highlighting for function parameters

v0.13.2 shows like this:

v0.13.3 shows like this:

The function parameters do not have their own style anymore. And something happened some releases ago that this parameters had a different color from the blue one that you can see on letand on @param.

It was in v0.10.0:

Parameters where highlighted in their unique color but ES6 class functions were not getting highlighted and @param flags on docblockr were just gray. I'd like that orange parameter color back on ^0.13.3 pleasee

Flow generics in argument breaks syntax highlighting

Repro:

var Foo = {
  first(): string {
    return 'Hello first';
  },

  second(
    ids: Array<number>,
    mutateFn: (record: MyRecord) => MyRecord
  ): string {
    return 'Hello second';
  },

  third(): string {
    return 'Hello third';
  }
};

Produces:
Screen shot of bug

Notice that mutateFn is not highlighted at all, the return keywords change colour, the braces are red, and third() is not highlighted correctly.

This is how it looks when using language-javascript-jsx):
language-javascript-jsx screen shot

.babelrc support

Hi,

Great package and pretty long awaited, thank you!

One thing is missing though. Most babel users use .babelrc containing babel configuration which can be different in different projects and even folders. So it would be great if language-babel could get that configuration from .babelrc about stage, blacklist transformers, optional transformers, etc. and apply it to corresponding scope this .babelrc is in.

Thanks again, great job!

language-babel does not appear in package manager

I'm not sure if this is a language-babel issue or a package manager issue, but language-babel does not appear in the package manager, and it seems to be the only package I have that's doing that. I'm using Atom 1.0.2 on OS X 10.11. Right now, the only way I can edit the package settings is by searching for the package on the "install" tab.

Suggested themes?

This is not really an issue, but I couldn't find a place for general discussion.

Do you have any suggested dark themes to use along with this package? The default Atom theme doesn't seem very nice, it has a lot of red in it. Seems like a lot of symbols are red.

grammar support for flowtype is missing

I've got a very small start towards this in this branch that only supports type annotations in argument lists. Return type annotations break things:

screenshot from 2015-07-18 03 08 47

Should the return types be added to the end patterns of all the varieties of function literals or is there a better way to accomplish that without so much repetition?

Uncaught TypeError: Cannot read property 'version' of null

This error pops up whenever babel will starting to transpile a file on save.

Atom Version: 1.0.2
System: Mac OS X 10.10.4
Thrown From: language-babel package, v0.10.3

Stack Trace

Uncaught TypeError: Cannot read property 'version' of null

At /Users/furkantunali/.atom/packages/language-babel/lib/transpiler.coffee:79

TypeError: Cannot read property 'version' of null
  at /Users/furkantunali/.atom/packages/language-babel/lib/transpiler.coffee:79:32
  at /Users/furkantunali/.atom/packages/language-babel/node_modules/babel-core/lib/api/node.js:121:5
  at FSReqWrap.readFileAfterClose [as oncomplete] (fs.js:379:3)

Commands

     -1:31.6.0 emmet:insert-formatted-line-break-only (atom-text-editor.editor.is-focused)
     -1:31.6.0 docblockr:parse-enter (atom-text-editor.editor.is-focused)
     -1:31.6.0 editor:newline (atom-text-editor.editor.is-focused)
     -1:31.2.0 emmet:insert-formatted-line-break-only (atom-text-editor.editor.is-focused)
     -1:31.2.0 docblockr:parse-enter (atom-text-editor.editor.is-focused)
     -1:31.2.0 editor:newline (atom-text-editor.editor.is-focused)
     -1:29.5.0 autocomplete-plus:confirm (atom-text-editor.editor.is-focused.autocomplete-active)
     -1:29.5.0 snippets:expand (atom-text-editor.editor.is-focused.autocomplete-active)
     -1:28.5.0 core:backspace (atom-text-editor.editor.is-focused)
     -1:28.2.0 linter:set-bubble-transparent (atom-text-editor.editor.is-focused)
     -1:26.5.0 core:save (atom-text-editor.editor.is-focused.autocomplete-active)
     -1:25.2.0 script:run (atom-text-editor.editor.is-focused)
     -0:10.1.0 editor:consolidate-selections (atom-text-editor.editor.is-focused)
     -0:10.1.0 core:cancel (atom-text-editor.editor.is-focused)
     -0:07.7.0 core:save (atom-text-editor.editor.is-focused)
     -0:05.0 core:copy (atom-notification.fatal.icon.icon-bug.native-key-bindings.has-detail.has-close.has-stack)

Config

{
  "core": {
    "projectHome": "/Users/furkantunali/Sites",
    "disabledPackages": [
      "deprecation-cop",
      "recent-files",
      "browser-refresh"
    ],
    "excludeVcsIgnoredPaths": false,
    "themes": [
      "one-light-ui",
      "one-light-syntax"
    ]
  },
  "language-babel": {
    "createTranspiledCode": true,
    "disableWhenNoBabelrcFileInPath": true,
    "babelSourcePath": "src",
    "babelTranspilePath": "dist",
    "externalHelpers": true,
    "suppressSourcePathMessages": true,
    "babelMapsAddUrl": false,
    "createMap": true
  }
}

Installed Packages

# User
atom-alignment, v0.12.1
atom-beautify, v0.28.8
atom-color-highlight, v3.0.9
autocomplete-paths, v1.0.2
autocomplete-phpunit, v1.0.2
browser-plus, v0.0.30
build, v0.42.0
docblockr, v0.7.3
editorconfig, v1.0.1
emmet, v2.3.12
file-icons, v1.5.8
file-types, v0.5.1
highlight-selected, v0.10.1
indentation-indicator, v0.6.0
language-SCSS, v0.4.0
language-apache, v1.3.0
language-babel, v0.10.3
language-css, v0.32.1
language-dotenv, v1.0.0
language-fish-shell, v1.0.2
language-generic-config, v0.2.0
language-gettext, v0.6.1
language-gitignore, v0.2.0
language-hosts, v0.1.2
language-ini, v1.11.0
language-javascript, v0.85.0
language-liquid, v0.4.0
language-mustache, v0.12.0
less-autocompile, v1.0.0
linter, v1.2.4
linter-bootlint, v0.0.6
linter-coffeelint, v1.0.0
linter-csslint, v0.0.14
linter-eslint, v3.0.1
linter-handlebars, v2.0.0
linter-htmlhint, v0.0.17
linter-jscs, v1.13.0
linter-jshint, vundefined
linter-jsonlint, v0.1.4
linter-less, v2.0.3
linter-php, v1.0.2
linter-phpcs, v1.0.6
linter-phpmd, v1.0.0
linter-pylint, v0.2.2
linter-recess, v0.0.1
linter-ruby, v0.1.6
linter-scss-lint, v2.0.0
linter-shellcheck, v0.0.8
local-history, v3.2.3
minimap, v4.12.1
minimap-color-highlight, v4.1.4
minimap-selection, v4.3.0
node-debugger, v1.1.6
pigments, v0.9.2
remote-atom, v1.2.6
sass-autocompile, v0.7.3
sass-compiler, v0.4.0
sass-watch, v0.3.1
script, v2.26.3
soft-wrap-indicator, v0.7.0
ssh-config, v0.10.1
tab-control, vundefined
tabs-to-spaces, v0.11.0
theme-switcher, v1.1.0

# Dev
No dev packages

Super calls scope

Would you restrict this scope just to be applied inside a class?

I want to give it another highlight color without overwriting variable declarations, imports, etc.

class {
  constructor () {
    super.foo();
  }
}

"No symbols found" in .jsx files

When editing a .jsx file, the symbols view (Cmd-R) is empty and displays the message "No symbols found". If I rename the same file to .js, the symbols view displays all the symbols I would expect it to. I've tried a variety of files, and it doesn't seem to be related to the contents at all; just the extension.

(Other than this minor issue, I'm really loving this syntax! Thanks for putting it together.)

Self closing tags

I am having a hard time in the grammar getting self closing tags to style properly.

Here is what they send up looking like:

Self Closing Tags

Checking the inspector, it appears that the closing tag just gets treated like raw text:

Inspector

Could we get the grammar to create a span for that self-closing end of the tag?

grammar support for arrow functions is inconsistent

screenshot from 2015-07-18 03 51 33

The gray => aren't getting any tags applied; the ones that are purple got storage.type.function.arrow.js. I agree with their coloring using one-dark-syntax because they're consistent with the function keyword, but shouldn't they technically be classified as operators?

Flow + extending Immutable Records = Broken syntax highlighting

Admittedly this is probably an edge case that might not occur a lot. Flow doesn't have first-class support for immutable-js records, so a slightly redundant hack to make Flow understand the types of the getters is to make a class that extends the record and adds Flow types as properties. The immutable-js docs also explicitly mentions that immutable records can be extended to add custom methods.

In this snippet, all syntax highlighting from the line under foo: Immutable.List<string> all the way to the end of the file is messed up:

class First extends Immutable.Record({
  foo: null,
}) {
  foo: string;

  getStuff(): string {
    return this.foo + '!';
  }
}

class Second extends Immutable.Record({
  foo: null,
}) {
  foo: Immutable.List<string>;

  getStuff(): string {
    return this.foo + '!';
  }
}

Screenshot
(notice different highlighting of second getStuff and return)

Modifying the Immutable.Record call so it's on a single line fixes the syntax highlighting:
Workaround 1

Splitting the creation of the record and the subclassing into two separate statements also works properly:
Workaround 2

Wrong ES6 method definition colors

Since 0.11.0, parentheses and the parameters themselves are displayed in different colors than before.

@0.10.5:
https://i.imgur.com/rlYOod1.png

@0.11.0 (and 0.11.4 as well):
https://i.imgur.com/XqxaqEg.png

Was this an intended change? Here's how it looks on Sublime Text 3 with the babel package installed (also notice the import and from keywords):
https://i.imgur.com/vxJC4q6.png

I'm using the oceanic-next-syntax syntax theme, if that matters.

Multi-line arrays are not auto-indented correctly

Currently it looks like this:

  mixins: [
  Stores.CurrentUser.mixin,
  Stores.CoachParticipants.mixin,
  Stores.Errors.mixin,
  Stores.LastViewed.mixin,
  Stores.ParticipantConversations.mixin,
  Stores.ParticipantGoal.mixin,
  Stores.ParticipantSuggestions.mixin,
  Stores.PendingUpdate.mixin,
  RouteHandlerKey
  ],

I expect it to look like this (how https://github.com/atom/language-javascript indents them):

  mixins: [
    Stores.CurrentUser.mixin,
    Stores.CoachParticipants.mixin,
    Stores.Errors.mixin,
    Stores.LastViewed.mixin,
    Stores.ParticipantConversations.mixin,
    Stores.ParticipantGoal.mixin,
    Stores.ParticipantSuggestions.mixin,
    Stores.PendingUpdate.mixin,
    RouteHandlerKey
  ],

Odd indentation for object/maps

Just wanted to bring this up, but when using the babel plugin the indentation gets a bit off with text-to-cursor location. This is mostly problematic with maps, where keys that have no quotes around them cause the cursor to be a few characters behind where is should be:
screen shot 2015-06-29 at 2 18 00 pm

The cursor (in the above image) is between the last double quote, but if I start typing characters appear after the comma.

If this is something that only i'm experiencing, let me know, but I'm only able to get it to work with the Babel plugin (but not the normal JS or JSX plugin). Also free to give any other info you might need!

Change content/class names of space inside JSX tags?

The space within JSX tags currently has a class string of .markup.raw.jsx when rendered in Atom. This causes a problem for any theme expecting .markup.raw to be used for raw HTML within a Markdown document (wesbos/cobalt2-atom#2).

.markup.raw (and .markup in general) seems to be mostly used for Markdown rather than XML/HTML. See atom/language-gfm/grammars/gfm.cson#L717. language-xml and language-html appear to have no reference to .markup at all.

I'm not sure what class string would be best for your project (which is why this isn't a PR), but for what it's worth, language-html and language-xml both fall back to their base scope names (.text.html.basic and .text.xml) for content within tags.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.