Use command conflicts with Standard Addition calls?

When the use command is placed above a call to standard additions — like choose folder or path to — it causes the script to error when compiling. If the command order is reversed, it works. anyone have insight into why and how to work around this problem?

Example 1

Use myLibrary : script "Hello"
set pathToDesktop to (path to desktop folder)
-- Error: A to:desktop can’t go after this path. (highlighting path to desktop)

set pathToDesktop to (path to desktop folder)
use myLibrary : script "Hello"
-- Successful compile

Example 2

Use myLibrary : script "Hello"
set pathToDesktop to choose folder
-- Error: Expected end of line, etc. but found identifier. (highlighting choose folder)

set pathToDesktop to choose folder
use myLibrary : script "Hello"
-- Successful compile

I am running MacOS High Seirra 10.13.1

Model: MacBook Pro with Touchbar (2016)
AppleScript: 2.7
Browser: Safari 604.3.5
Operating System: Other

When the use expression is used in AppleScript the interpreter knows that it is a “new” AppleScript format and the script is interpreted differently. When you use an scripting addition command before the use expression the old format is used. The new applescript format has scripting additions turned off by default while in the old format it is turned on.

The reason it behaves this way is because determination between new and old format is done while parsing long before semantic analyzing.

To answer your question. When using the use expression and want to make use of scripting additions you should use the expression:

use scripting additions

So in your example you should always use:

use myLibrary : script "test"
use scripting additions
set pathToDesktop to (path to desktop folder)

Of course. Thank you!