Search code examples
javascriptimportecmascript-6

ES6 import - aliasing a string member?


I'm just double-checking that the following is not valid syntax as an ES6 import:

import { 'stream/streamItem.html' as StreamItemTemplate } from 'common/templates';

I'd really prefer to write it that way as opposed to something like:

import { stream_streamItem_html as StreamItemTemplate } from 'common/template';

but it appears that strings are not valid member declarations even when aliasing?


Solution

  • According to the spec, stream_streamItem_html in your example is an IdentifierName. An IdentifierName is, according to the spec, (cite) "interpreted according to the Default Identifier Syntax", which means StringLiterals are not allowed.