GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | ||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | ||||||||||
GeezerVison is showing github.com — Support ES6 import and export declarations by ahejlsberg · Pull Request #1983 · microsoft/TypeScript Conversation
Member
This PR adds support for ES6 import and export declarations. Supported import forms include: import defaultBinding from "foo"; // Import foo's default export import * as foo from "foo"; // Make a single binding for the entire namespace import { a, b as x } from "foo"; // Make local bindings for individually imported members Supported export forms include: export { a, b as x }; // Export local entities export { a, b as x } from "foo"; // Re-export individual members of foo without local bindings export * from "foo"; // Re-export all members of foo without local bindings The following export forms are not yet implemented: export default class {...} export default function(...) {...} export default someExpression; ES6 modules are very similar to TypeScript's external modules. ES6 modules permit individual entities to be exported using an Given the following external module export function foo(s: string) {} export function bar(s: string) {} export default function(x: number) {} here are some ways it might be imported: import * as utils from "utils"; // Namespace import utils.foo("hello"); utils.bar("world"); import { foo, bar as baz } from "utils"; // Individual named imports foo("hello"); baz("world"); import func from "utils"; // Import of default export func(42); import func, { foo, bar } from "utils"; // Combination func(42); foo("hello"); bar("world"); When ES6 modules are compiled down-level for ES3 or ES5 (which is currently the only supported way), a module cannot have both individual exports and a default export.
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactionsNamedImports :
{ }
{ ImportsList }
{ ImportsList , }
ImportsList :
ImportSpecifier
ImportsList , ImportSpecifier
ImportSpecifier :
ImportedBinding
IdentifierName as ImportedBinding
Conflicts:
src/compiler/parser.ts
…void creating missing symbols Missing symbols are defined when the declaration doesnt have name, so if we created node for missing identifier it would end up binding symbol with name (Missing) …claration This helps binder to use it directly to bind the default binding Conflicts: src/compiler/checker.ts
Member
All reactions
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page.
Member
Author
All reactions
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page.
Member
Author
All reactions
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page.
Member
Author
All reactions
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is it possible to have a situation when name does not appear in current file but exists on the top level in some another file (like
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactions
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good point
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactions
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, we should probably check
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactions
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactions
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, we should do that.
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactions
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the new import and export node types should be in this list.
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactionsConflicts: src/compiler/diagnosticInformationMap.generated.ts src/compiler/diagnosticMessages.json src/compiler/emitter.ts tests/baselines/reference/APISample_compile.js tests/baselines/reference/APISample_compile.types tests/baselines/reference/APISample_linter.js tests/baselines/reference/APISample_linter.types tests/baselines/reference/APISample_transform.js tests/baselines/reference/APISample_transform.types tests/baselines/reference/APISample_watcher.js tests/baselines/reference/APISample_watcher.types tests/baselines/reference/recursiveClassReferenceTest.js.map tests/baselines/reference/recursiveClassReferenceTest.sourcemap.txt
Anders Hejlsberg (ahejlsberg)
added a commit
that referenced
this pull request
Support ES6 import and export declarations
All reactions
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page.
This was referenced
Closed
All reactions
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page.
|
There was an error while loading. Please reload this page.
|
Marc Wensauer (@daslicht) First, you need a loader that interpolates them into a named module export, usually this is the export named declare module '*.handlebars' { // export matching the shape produced by the loader. } In your case, it looks like using ES2015 module syntax is not supported, and you are stuck with |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Any example on that ? please? I am trying to use handlebars in an TypeScript setup |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
|
Marc Wensauer (@daslicht) say I were using SystemJS to load and bundle my application. In that case I would have a setup like this (simplified) systemjs.config.js SystemJS.config({ meta: { '*.handlebars': { loader: 'text-loader-plugin' } } }); If I were using webpack it would look like this (simplified) webpack.config.js module.exports = { loaders: [ { test: /\.handlebars$/, loader: 'text-loader-plugin' } ] }; The plugin would sort of look like this (changed and simplified for exposition) text-loader-plugin.js export default function (path) { const content = load(path); // XHR or fs.readFile return { 'default': content }; } Then in my TypeScript project I would have a file like globals.d.ts declare module '*.handlebars' { export default ''; } Then I would use it like this app/home.ts import template from 'app/home.handlebars'; |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
|
OK, thank you !, I keep trying, my approach was using the |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
There was an error while loading. Please reload this page.