Skip to content

Commit

Permalink
Comment on how import statements work
Browse files Browse the repository at this point in the history
  • Loading branch information
pavelvasev committed Mar 17, 2015
1 parent c65dae1 commit 5459537
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions src/import.js
@@ -1,6 +1,8 @@
/* @license
Copyright (c) 2011 Lauri Paimen <lauri@paimen.info>
Copyright (c) 2015 Pavel Vasev <pavel.vasev@gmail.com> - initial
and working import implementation.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
Expand Down Expand Up @@ -68,6 +70,7 @@ function parseQML(file) {
/**
* Get URL contents. EXPORTED.
* @param url {String} Url to fetch.
* @param skipErrorLogging {boolean} if true, the failed fetch is not error (used with conjuction of importPathList).
* @private
* @return {mixed} String of contents or false in errors.
*/
Expand All @@ -86,7 +89,7 @@ getUrlContents = function (url,skipErrorLogging) {
// because without exception, "" then goes to parser, and it failes with strange errors.
if (!skipErrorLogging)
throw e;
return "";
return false;
}
return xhr.responseText;
}
Expand All @@ -97,8 +100,24 @@ getUrlContents = function (url,skipErrorLogging) {
* @return {Object} Object, where .internals lists qmldir internal references
* and .externals lists qmldir external references.
*/

/* Note on how importing works.
* parseQML gives us `tree.$imports` variable, which contains information from `import` statements.
* After each call to parseQML, we call engine.loadImports(tree.$imports).
It in turn invokes readQmlDir() calls for each import, with respect to current component base path and engine.importPathList().
* We keep all component names from all qmldir files in global variable `engine.qmldir`.
* In construct() function, we use `engine.qmldir` for component url lookup.
Reference import info: http://doc.qt.io/qt-5/qtqml-syntax-imports.html
Also please look at notes and TODO's in qtcore.js::loadImports() and qtcore.js::construct() methods.
*/

readQmlDir = function (url) {
var qmldir = getUrlContents(url + "/qmldir"), // Modifies url here!
var qmldir = getUrlContents(url + "/qmldir", true), // loading url contents with skipping errors
lines,
line,
internals = {},
Expand Down

0 comments on commit 5459537

Please sign in to comment.