Нашли строку, но не знаете что с ней делать? Поставьте перед сбойной строкой MsgBox с выводом значения переменной, чтоб увидеть, являются ли данные тем, что необходимо получить. И если переменная является массивом, то используйте _ArrayDisplay, добавив в начало скрипта
Если скрипт был найден на форуме, то попытайтесь выяснить версию AutoIt3, с которой использовался скрипт, например по дате поста. Проверьте чтобы все необходимые скрипту
Если окно ошибки указывает на переменную являющуюся элементом массива, даже если вы уверены что с массивом всё в порядке, то очень вероятно, что цикл использует индекс превышающий существующие индексы в массиве. Используйте
Ниже приведен полный список фатальных ошибок AutoIt, возникающих при неправильном написании скриптов пользователем. Всего 74
downloaded AutoIT, and got it working, issue with your FileInstall function, you opened a brace, but never closed it, but reading up, i found fileCopy works better.
If $WATCH = True Then ; New USB Drive Was Detected, Time to Find it's Letter $New = FindNewDrive() $Label = DriveGetLabel($New) $MyDrive = $New & "" FileCopy("C:test.bmp", $MyDrive) EndIf
Heres the copy i have working.
Dim $DBT_DEVICEARRIVAL = "0x00008000" Dim $DBT_DEVICECOMPLETEREMOVAL = "0x00008004" Dim $USB_ATTENTION = "0x00000007" Dim $WM_DEVICECHANGE = 0x0219 Dim $Drives Dim $Drive_Type = "ALL"; Set to ALL because some USB Drives are detected as Fixed Disks, and we don't want to miss those Dim $WATCH = False Dim $MyDrive = "STUFF" ;Get Initial List of Drives to Check Against UpdateDrives() ;Setup The GUI to watch for the DeviceChange Event GUICreate("") GUIRegisterMsg($WM_DEVICECHANGE, "DeviceChange") Func DeviceChange($hWndGUI, $MsgID, $WParam, $LParam) Switch $WParam Case $USB_ATTENTION ; This only happens when USB drives are inserted, so I use it to tell the difference between these and CDROMs $WATCH = True Case $DBT_DEVICECOMPLETEREMOVAL ; Whenever a Drive is Removed, Update the Drive List UpdateDrives() Case $DBT_DEVICEARRIVAL ; A drive was inserted ; Use $WATCH to tell if this was a CDROM or USB ; $WATCH = True, USBs ; $WATCH = False, CDROM If $WATCH = True Then ; New USB Drive Was Detected, Time to Find it's Letter $New = FindNewDrive() $Label = DriveGetLabel($New) $MyDrive = $New & "" FileCopy("C:test.bmp", $MyDrive) EndIf ; Now Reset Drive List so more insertions can also be detected accurately UpdateDrives() EndSwitch EndFunc;==>DeviceChange ; This just jumps through the new Drive List, comparing them until it finds the entry that is in the new one that isn't in the old one Func FindNewDrive() $Temp = DriveGetDrive( "REMOVABLE" ) For $i = 1 to $Temp[0] $Old = False For $j = 1 to $DRIVES[0] If $DRIVES[$j] == $Temp[$i] Then $Old = True Next If $Old == False Then Return $Temp[$i] Next EndFunc;==>FindNewDrive ; Just to keep things neat, and so if Variables Ever Change, this makes updating easier Func UpdateDrives() $Drives = DriveGetDrive( $Drive_Type ) EndFunc;==>UpdateDrives ; Main Loop to Keep the Program Open ; No Real Way of ending this program, except for just killing the process ; Which is what I want, an always on backup for my drive every time I insert it While 1 $GuiMsg = GUIGetMsg() ; This is needed because the watch event above not only triggers before a USB Drive is inserted/removed, ; but also AFTER insertion too, and if not reset, a subsequent CD insertion will trigger it again. ; So, every second, we reset $WATCH, to keep things clean Sleep (1000) $WATCH = False WEnd
Форум программистов Vingrad
Модераторы: PILOT |
Поиск: |
|
Пожалуйста помогите с AutoIt! скрипт |
Опции темы |
zomba |
|
||
Новичок Профиль Репутация: нет
|
Извините пожалуйста, если тема не в том разделе. Line 1 (File «C:Program FilesAutoIt3Examplesrefresh.au3»): Error: Error parsing function call. Я всё сделал по мануалу, по идее скрипт должен запускаться! Пробовал вместо F5 вставить BROWSER_REFRESH, тоже самое. |
||
|
|||
zomba |
|
||
Новичок Профиль Репутация: нет
|
И ещё, скажите плиз, как зациклить скрипт. Или надо тупо тыщу раз повторить его? |
||
|
|||
Kee_Keekkenen |
|
||
Новичок Профиль Репутация: нет
|
зайди на официальный сайт автоита на нем есть русский хелп — очень полезная вещь.. |
||
|
|||
|
Правила форума «Объявления о найме специалистов» | |
В случае невыполнения данных правил Ваши сообщения могут быть удалены без предупреждения. Полный спискок правил. С уважением, BearBeer. |
0 Пользователей читают эту тему (0 Гостей и 0 Скрытых Пользователей) |
0 Пользователей: |
« Предыдущая тема | Объявления о найме специалистов | Следующая тема » |
Background
Mentioned in the previous post, we have upgraded babel 7 to support the new Flow syntax.
foobar<Type>(x)
is now call foobar with x, and type parameter Type
rather than (foobar < Type) > x)
is the result of foobar smaller than Type, greater than x?.
Everything is great, until a weird runtime error caught us off guard.
ReferenceError: XType is not defined
export function foobar<XType>(baz);
^ ReferenceError: XType is not defined
The first time I saw this error, my first impression was that I forgot to import XType
, so I scrolled to the top of the document. But, alas, I did import XType
.
So what is going on? 🤷
I clicked into the error,
export function foobar < XType > baz;
looked at me innocently. I knew something was wrong. XType
wasn’t stripeed by babel!
Shameless plug: If you read my eslint for flow syntax, you should be able to come to the same conclusion! 😅
So I checked the @babel/plugin strip-flow-types, I realise there’s a all
option that I had missed out, basically it says,
only parse Flow-specific features if a
@flow
pragma is present atop the file
It seems that in my file,
/** @module foobar */
// ...
export function foobar<XType>(baz);
I had a innocent looking /** @module */
comment above // @flow
that breaks my babel plugin!
So the quick fix is to either:
- Move
// @flow
comment above/** @module foobar */
, or - Set
all: true
in@babel/plugin-transform-flow-strip-types
.
Either way, it solves the issue.
However, one thing bothers me:
My Flow works perfectly fine with an extra comment on top
// @flow
, it still typechecks and provides auto-suggestions.
So, the logic for @babel/plugin-transform-flow-strip-types
and Flow to determine whether a file is a Flow file or not is different!
And as a frequent user of Open Source libraries, this is something I think I can should fix, for the betterment of the JavaScript Open Source world 😅. I always imagine there’s another innocent front-end developer across the world like me stumbled upon a perplexing bug, if only me let the bug go with a workaround/patch.
There’s so much to achieve if we, not just consume the effort of others from the Open Source, but to also contribute into it.
Game Plan
So, to fix this bug, one simply has to:
- Read Flow’s source code and understand the logic
- Read @babel/plugin-transform-strip-flow-type’s source code and understand the logic
- Make changes to babel code
- Send a MR and brag about it 😎
Whether this is achieveable at my current level, that’s a different story.
But one has nothing to lose to try and fail.
Flow
I’ve read a bit of Flow source code previously, mainly to fix a bad developer experience I had with flowconfig previously. I had to learn OCaml, which was a fad a while ago because of ReasonML, to understand Flow source code.
So, this time around, I am much more comfortable to dig the code to find out the information I want.
I searched for the term "@flow"
, which ended me up with this function, extract_docblock
which returns me the information of whether @flow
is present in the file. And I dug further, I ended up with the annonymous function that extract_docblck
returns.
Allow me to loosely translate the logic into some pseudo JavaScript:
const extract_docblock = ({ maxTokens, filename, content }) => {
const file = read(filename);
for (let i = maxTokens; i > 0; i--) {
const token = file.nextToken();
switch (token.type) {
case 'string':
case 'semicolon':
continue;
case 'comment':
if (isFlowComment(token)) {
return flowPragmaType(token);
}
break;
default:
return null;
}
}
};
In human language:
Flow will read maxTokens
number of tokens, look for comments that matches @flow
, if it encounters any order tokens, it will bail out early, with the exception of string and semicolon.
So,
and
is considered as a valid Flow file.
But
or
is not.
Babel
At first, I thought that the logic would be in @babel/transform-strip-flow-types
, but apparently, its not.
I discovered that by realising that the source code of @babel/transform-strip-flow-types did not include anything about the all
options, and this plugin extends the @babel/plugin-syntax-flow, which I knew fairly well that syntax plugins in babel does nothing but to enable syntax switch of the @babel/parser
. The bulk of the logic lies within the @babel/parser
‘s flow plugin.
That was all because I contributed to @babel/parser
before.
And here we are in babel-parser, and the line that caught my attention is this:
addComment(comment: N.Comment): void {
if (this.flowPragma === undefined) {
// Try to parse a flow pragma.
const matches = FLOW_PRAGMA_REGEX.exec(comment.value);
if (!matches) {
this.flowPragma = null;
} else if (matches[1] === "flow") {
this.flowPragma = "flow";
} else if (matches[1] === "noflow") {
this.flowPragma = "noflow";
} else {
throw new Error("Unexpected flow pragma");
}
}
return super.addComment(comment);
}
So, the babel’s logic of getting a Flow pragma is that as soon as the first comment encountered, we parse the comment and we turn on the Flow syntax switch.
This is the reason why if we have a comment before // @flow
, we will not treat the file as a valid Flow file.
Interesting enough, this means that if we write
foobar < XType > 1;
foobar<XType>(1);
the first half of the code before // @flow
was parsed as a normal JS code, and the second half after // @flow
was parsed as a Flow code.
You can see this clearly with my recently build ASTExplorer clone for babel.
(I built it with React + Hooks over a long weekend, which I will share about how did it in the future.).
You can see that the first expression is a BinaryExpression
but the second expression is a CallExpression
;
Make changes to the babel code
Now step 3, make changes to babel code. So I decided to open an issue and started fixing the code. Surprisingly, someone else had reported the issue a few months ago, and the issue was still opened.
So I explained what I had discovered, and tried to propose a solution. Well, after some struggle, I realised I am still a bit behind from being able to fix this code.
So how?
I submitted a PR with a big WIP, because I didn’t know how to look ahead n
tokens and determine the flowPragma
flag before babel
starts parsing the code. I explored around the babel-parser
source code, uncover new concepts that I never knew before. It took me a day to contemplate and fiddle around, until something sparked me.
I realised I do not have to follow exactly Flow’s logic in order to achieve similar behaviour. That’s when I submitted another PR and closed the previous one. (You can check it out if you are curious about it).
And finally, the fix has merged into babel v7.4.4! 🎉🎉
And I can’t wait to try all the edge cases that I have fixed in babel repl:
'use strict'
; before// @flow
- comments before
//@flow
- first comment is
//@flow
, but in the middle of the file
Closing Remark
Well, I am sorry that I am going to stop here, because the issue is still opened, but I hoped you enjoy the detective journey along the way of hunting this bug.
If you encountered similar issues, you can patch it first with the solution I mentioned earlier. And do follow the Github issue, I will do my best to fix this.
If you encountered similar issues, please upgrade babel to v7.4.4.
The best thing about open source is that the source code is open. As part of the JS community, we should not just reap the efforts of the community when we are building our next billion dollar idea, we should also contribute back so that the community as a whole can grow and improve together.
As usual, here are the list of references for this article:
- Blog: Errors encountered upgrading Flow v0.85
- My eslint doesn’t work with for flow 0.85’s explicit type argument syntax
- Docs: Upgrading Babel v7
- Docs: @babel/transform-plugin-flow-strip-types
- Docs: ReasonML
- Code: Flow Parsing Service
- Issue: Parsing error when calling generic functions with type arguments when flow pragma is not first comment