[英]How to break long import statements into multiple lines in ES6?
I have a pretty long import statement in my JavaScript (ES6) file:我的 JavaScript (ES6) 文件中有一个很长的 import 语句:
import { A, B, C, D } from '../path/to/my/module/in/very/far/directory/'
Is it OK to add new lines like this?像这样添加新行可以吗?
import { A, B, C, D } from
'../path/to/my/module/in/very/far/directory'
If not, is there any other way to write clean (keeping my code within 80 columns) import statements in ES6 syntax using Babel?如果没有,是否还有其他方法可以使用 Babel 以 ES6 语法编写干净的(将我的代码保持在 80 列内)导入语句?
Here are the results from my test using ESLint
.以下是我使用
ESLint
测试结果。
ESLINT PASSED ESLINT通过
import fs
from 'fs';
ESLINT PASSED ESLINT通过
import
fs
from
'fs';
ESLINT PASSED ESLINT通过
import {
moduleName
} from './my/module/file';
And the above code executes fine.上面的代码执行得很好。 I think you are good to go!
我认为你很高兴去!
Yes, the ES6 spec does allow whitespace - which includes newlines - between every token (unless otherwise restricted).是的,ES6 规范确实允许在每个标记之间使用空格(包括换行符)(除非另有限制)。 Automatic semicolon insertion will not mess with you inside of import declarations either, so you're free to do
自动分号插入也不会在导入声明中干扰您,因此您可以自由地做
import
{
A
,
B
,
C
,
D
}
from
'../path/to/my/module/in/very/far/directory/'
;
or anything that is less extreme and better indented :-)或任何不那么极端和更好缩进的东西:-)
You can use following syntax:您可以使用以下语法:
import {
CanActivate, CanActivateChild, CanDeactivate, CanLoad, Route,
UrlSegment, ActivatedRouteSnapshot, RouterStateSnapshot, UrlTree
} from '@angular/router';
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.