You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This proposal adds a second… operand(?) to the import(...) expression, an options bag. As I understand it, it is meant to be an extensible mechanism that other language enhancements that modify the importing process may take advantage of.
As currently specified, EvaluateImportCall is defined to ignore the presence of unrecognized keys in the options bag. As far as this proposal is concerned, this is fine, because assertions are meant to be applied opportunistically, and if they pass, they don’t change the semantics of importing; however, there are already proposals in the works building upon this one that do. For example, https://github.com/tc39/proposal-import-reflection may import the module as an entirely different object.
My question is, how is user code to know whether an import option was actually taken into account by the host? How should it prevent a situation where an import call ostensibly returns success, but with the wrong semantics? (e.g. importing a JSON file as if it were an ECMAScript module)
The text was updated successfully, but these errors were encountered:
But this is not a very convenient option, and it is still dangerous in that the lack of support is only detected after the import is complete, which may have had already triggered unwanted side effects. Though at least this trick would allow probing for features in controlled conditions:
constisImportOptionSupported=option=>{letsupported=false;import(// or `module {}`, per <https://github.com/tc39/proposal-js-module-blocks>'data:text/javascript,',{get[option](){supported=true;}}).catch(()=>{});returnsupported;};constgetSupportedImportOptions=()=>{constfeatures=Object.create(null);import('data:text/javascript,',newProxy({},{get(target,key,proxy){features[key]=true;}})).catch(()=>{});returnfeatures;};
Though that still may fail if any conditionally-checked option keys are added.
This proposal adds a second… operand(?) to the
import(...)
expression, an options bag. As I understand it, it is meant to be an extensible mechanism that other language enhancements that modify the importing process may take advantage of.As currently specified, EvaluateImportCall is defined to ignore the presence of unrecognized keys in the options bag. As far as this proposal is concerned, this is fine, because assertions are meant to be applied opportunistically, and if they pass, they don’t change the semantics of importing; however, there are already proposals in the works building upon this one that do. For example, https://github.com/tc39/proposal-import-reflection may import the module as an entirely different object.
My question is, how is user code to know whether an import option was actually taken into account by the host? How should it prevent a situation where an
import
call ostensibly returns success, but with the wrong semantics? (e.g. importing a JSON file as if it were an ECMAScript module)The text was updated successfully, but these errors were encountered: