I have a big fat object that is structured like this (using CJS format to remove all ambiguity):
// big-fat-package.js
module.exports = {
runtime: {
compile: function() {},
partials: {
'non-valid-identifier-property-0': function() {},
'non-valid-identifier-property-1': function() {},
'non-valid-identifier-property-2': function() {},
'non-valid-identifier-property-3': function() {},
'non-valid-identifier-property-n': function() {}
}
}
}
In a CJS world, to import a single partial I'd do this:
var tpl0 = require('big-fat-package').runtime.partials['non-valid-identifier-property-0'];
And multiple, something like:
var partials = require('big-fat-package/runtime').runtime.partials
var tpl0 = partials['non-valid-identifier-property-0'];
var tpl1 = partials['non-valid-identifier-property-1'];
So far so good. But is it possible to do this using ES6 import
aliasing? Something like (note: this isn't valid syntax)...
import { runtime as { partials as { 'non-valid-identifier-property-0' as tpl0 } } } from 'big-fat-package';
Seems like it's impossible to:
- alias a property more than one level deep using ES6 import.
- reference a non-valid identifier within an
import
.
Is this true, or just my lack of experience?
The shortest, yet perhaps most incomprehensible due to right-to-left, appears to be:
import { runtime } from 'big-fat-package';
const {
'non-valid-identifier-property-0': tpl0,
'non-valid-identifier-property-1': tpl1
} = runtime.partials;
Anyone have better ideas?